Skip to content

Commit 7e820cb

Browse files
authored
Merge pull request #15 from budimanjojo/14
feat: allow not creating aliases
2 parents fa143c4 + 1978e28 commit 7e820cb

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ fisher install budimanjojo/tmux.fish
5555
| `fish_tmux_fixterm_with_256color` | `$TERM` to use for 256-color terminals (default: `tmux-256color` if available, `screen-256color` otherwise) |
5656
| `fish_tmux_iterm2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) |
5757
| `fish_tmux_unicode` | Set `tmux -u` option to support unicode (default: `false`) |
58+
| `fish_tmux_no_alias` | If set to `true`, aliases except for `tmux` are not created (default: `unset`) |
5859

5960
## Configuration
6061

@@ -71,6 +72,7 @@ Remember to order the `set` command after `$PATH` is set correctly for `tmux` co
7172

7273
## Difference with ZSH Version
7374

75+
- Added `fish_tmux_no_alias` variable to disable creating aliases except for `tmux` alias because it is the core of this plugin.
7476
- Autostart is a [fish function](https://fishshell.com/docs/current/cmds/function.html) with `--on-variable` option. This means the autostart will run as soon as you change the variable `$fish_tmux_autostart` to `true`. This lets you decide when to start the function. This is needed due to how `fish` handle the order of execution. Fish will always load everything inside `$__fish_config_dir/conf.d` before running user config. This leads to issue such as [tmux not found](https://github.com/budimanjojo/tmux.fish/issues/4).
7577
- Most configuration variables are local to the function when being run. So your current shell won't be filled with `fish_tmux_xxx` variables.
7678

conf.d/tmux.fish

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,45 @@ else
1111
end
1212

1313
# aliases
14-
function _build_tmux_alias
15-
set alias_name $argv[1]
16-
set tmux_cmd $argv[2]
17-
set ts_flag $argv[3]
18-
set full_cmd "command tmux $tmux_cmd $ts_flag"
19-
20-
eval "
21-
function $alias_name --wraps='$full_cmd' --description 'alias $alias_name=$full_cmd'
22-
# check if the first argument for this function is empty or starts with '-'
23-
if test (count \$argv) -eq 0 || test (string sub -l 1 \$argv[1]) = '-'
24-
command tmux $tmux_cmd \$argv
25-
else
26-
$full_cmd \$argv
14+
alias tmux=_fish_tmux_plugin_run
15+
function _fish_tmux_create_aliases --on-variable fish_tmux_no_alias
16+
if test "$fish_tmux_no_alias" != true
17+
function _build_tmux_alias
18+
set alias_name $argv[1]
19+
set tmux_cmd $argv[2]
20+
set ts_flag $argv[3]
21+
set full_cmd "command tmux $tmux_cmd $ts_flag"
22+
23+
eval "
24+
function $alias_name --wraps='$full_cmd' --description 'alias $alias_name=$full_cmd'
25+
# check if the first argument for this function is empty or starts with '-'
26+
if test (count \$argv) -eq 0 || test (string sub -l 1 \$argv[1]) = '-'
27+
command tmux $tmux_cmd \$argv
28+
else
29+
$full_cmd \$argv
30+
end
31+
end
32+
"
2733
end
34+
35+
alias tds=_fish_tmux_directory_session
36+
alias tksv="command tmux kill-server"
37+
alias tl="command tmux list-sessions"
38+
alias tmuxconf="$EDITOR $fish_tmux_config"
39+
# `-t` and `-s` flag for tmux commands require argument
40+
# so we remove the flag when called without argument and run normally when called with argument
41+
# see: https://github.com/ohmyzsh/ohmyzsh/issues/12230
42+
_build_tmux_alias "ta" "attach" "-t"
43+
_build_tmux_alias "tad" "attach -d" "-t"
44+
_build_tmux_alias "ts" "new-session" "-s"
45+
_build_tmux_alias "tkss" "kill-session" "-t"
46+
47+
functions -e _build_tmux_alias # remove this function after use
48+
else
49+
functions -e tds tksv tl tmuxconf ta tad ts tkss
2850
end
29-
"
3051
end
31-
32-
alias tmux=_fish_tmux_plugin_run
33-
alias tds=_fish_tmux_directory_session
34-
alias tksv="command tmux kill-server"
35-
alias tl="command tmux list-sessions"
36-
alias tmuxconf="$EDITOR $fish_tmux_config"
37-
# `-t` and `-s` flag for tmux commands require argument
38-
# so we remove the flag when called without argument and run normally when called with argument
39-
# see: https://github.com/ohmyzsh/ohmyzsh/issues/12230
40-
_build_tmux_alias "ta" "attach" "-t"
41-
_build_tmux_alias "tad" "attach -d" "-t"
42-
_build_tmux_alias "ts" "new-session" "-s"
43-
_build_tmux_alias "tkss" "kill-session" "-t"
44-
45-
functions -e _build_tmux_alias # remove this function after use
52+
_fish_tmux_create_aliases
4653

4754
# wrapper function for tmux
4855
function _fish_tmux_plugin_run

0 commit comments

Comments
 (0)