diff --git a/README.md b/README.md index dfee1ee..ecf44d6 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ fisher install budimanjojo/tmux.fish | `fish_tmux_fixterm_with_256color` | `$TERM` to use for 256-color terminals (default: `tmux-256color` if available, `screen-256color` otherwise) | | `fish_tmux_iterm2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | | `fish_tmux_unicode` | Set `tmux -u` option to support unicode (default: `false`) | +| `fish_tmux_no_alias` | If set to `true`, aliases except for `tmux` are not created (default: `unset`) | ## Configuration @@ -71,6 +72,7 @@ Remember to order the `set` command after `$PATH` is set correctly for `tmux` co ## Difference with ZSH Version +- Added `fish_tmux_no_alias` variable to disable creating aliases except for `tmux` alias because it is the core of this plugin. - 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). - Most configuration variables are local to the function when being run. So your current shell won't be filled with `fish_tmux_xxx` variables. diff --git a/conf.d/tmux.fish b/conf.d/tmux.fish index 33a5503..e6f3358 100644 --- a/conf.d/tmux.fish +++ b/conf.d/tmux.fish @@ -11,38 +11,45 @@ else end # aliases -function _build_tmux_alias - set alias_name $argv[1] - set tmux_cmd $argv[2] - set ts_flag $argv[3] - set full_cmd "command tmux $tmux_cmd $ts_flag" - - eval " - function $alias_name --wraps='$full_cmd' --description 'alias $alias_name=$full_cmd' - # check if the first argument for this function is empty or starts with '-' - if test (count \$argv) -eq 0 || test (string sub -l 1 \$argv[1]) = '-' - command tmux $tmux_cmd \$argv - else - $full_cmd \$argv +alias tmux=_fish_tmux_plugin_run +function _fish_tmux_create_aliases --on-variable fish_tmux_no_alias + if test "$fish_tmux_no_alias" != true + function _build_tmux_alias + set alias_name $argv[1] + set tmux_cmd $argv[2] + set ts_flag $argv[3] + set full_cmd "command tmux $tmux_cmd $ts_flag" + + eval " + function $alias_name --wraps='$full_cmd' --description 'alias $alias_name=$full_cmd' + # check if the first argument for this function is empty or starts with '-' + if test (count \$argv) -eq 0 || test (string sub -l 1 \$argv[1]) = '-' + command tmux $tmux_cmd \$argv + else + $full_cmd \$argv + end + end + " end + + alias tds=_fish_tmux_directory_session + alias tksv="command tmux kill-server" + alias tl="command tmux list-sessions" + alias tmuxconf="$EDITOR $fish_tmux_config" + # `-t` and `-s` flag for tmux commands require argument + # so we remove the flag when called without argument and run normally when called with argument + # see: https://github.com/ohmyzsh/ohmyzsh/issues/12230 + _build_tmux_alias "ta" "attach" "-t" + _build_tmux_alias "tad" "attach -d" "-t" + _build_tmux_alias "ts" "new-session" "-s" + _build_tmux_alias "tkss" "kill-session" "-t" + + functions -e _build_tmux_alias # remove this function after use + else + functions -e tds tksv tl tmuxconf ta tad ts tkss end - " end - -alias tmux=_fish_tmux_plugin_run -alias tds=_fish_tmux_directory_session -alias tksv="command tmux kill-server" -alias tl="command tmux list-sessions" -alias tmuxconf="$EDITOR $fish_tmux_config" -# `-t` and `-s` flag for tmux commands require argument -# so we remove the flag when called without argument and run normally when called with argument -# see: https://github.com/ohmyzsh/ohmyzsh/issues/12230 -_build_tmux_alias "ta" "attach" "-t" -_build_tmux_alias "tad" "attach -d" "-t" -_build_tmux_alias "ts" "new-session" "-s" -_build_tmux_alias "tkss" "kill-session" "-t" - -functions -e _build_tmux_alias # remove this function after use +_fish_tmux_create_aliases # wrapper function for tmux function _fish_tmux_plugin_run