Prefer set and eval in fish binding

This commit is contained in:
mingmingrr 2021-07-30 02:46:53 -04:00
parent 0c2c7e2f86
commit f1242d192a
1 changed files with 22 additions and 22 deletions

View File

@ -10,7 +10,7 @@ function powerline-setup
return 0 return 0
end end
if test -z "$POWERLINE_CONFIG_COMMAND" if not set -q POWERLINE_CONFIG_COMMAND
if which powerline-config >/dev/null if which powerline-config >/dev/null
set -g POWERLINE_CONFIG_COMMAND powerline-config set -g POWERLINE_CONFIG_COMMAND powerline-config
else else
@ -18,9 +18,9 @@ function powerline-setup
end end
end end
if env $POWERLINE_CONFIG_COMMAND shell --shell=fish uses prompt if eval $POWERLINE_CONFIG_COMMAND shell --shell=fish uses prompt
if test -z "$POWERLINE_COMMAND" if not set -q POWERLINE_COMMAND
set -g POWERLINE_COMMAND (env $POWERLINE_CONFIG_COMMAND shell command) set -g POWERLINE_COMMAND (eval $POWERLINE_CONFIG_COMMAND shell command)
end end
function _powerline_set_default_mode --on-variable fish_key_bindings function _powerline_set_default_mode --on-variable fish_key_bindings
if test $fish_key_bindings != fish_vi_key_bindings if test $fish_key_bindings != fish_vi_key_bindings
@ -31,18 +31,18 @@ function powerline-setup
end end
function _powerline_update --on-variable POWERLINE_COMMAND function _powerline_update --on-variable POWERLINE_COMMAND
set -l addargs "--last-exit-code=\$status" set -l addargs "--last-exit-code=\$status"
if test -z "$pipestatus" if set -q pipestatus
set addargs "$addargs --last-pipe-status=\$status"
else
set addargs "$addargs --last-pipe-status=\"\$pipestatus\"" set addargs "$addargs --last-pipe-status=\"\$pipestatus\""
else
set addargs "$addargs --last-pipe-status=\$status"
end end
set -l addargs "$addargs --jobnum=(jobs -p | wc -l)" set -l addargs "$addargs --jobnum=(jobs -p | wc -l)"
if test -z "$fish_pid" if set -q fish_pid
set addargs "$addargs --renderer-arg=client_id=\$fish_pid"
else
# One random value has an 1/32767 = 0.0031% probability of having # One random value has an 1/32767 = 0.0031% probability of having
# the same value in two shells # the same value in two shells
set addargs "$addargs --renderer-arg=client_id="(random) set addargs "$addargs --renderer-arg=client_id="(random)
else
set addargs "$addargs --renderer-arg=client_id=\$fish_pid"
end end
set -l addargs "$addargs --width=\$_POWERLINE_COLUMNS" set -l addargs "$addargs --width=\$_POWERLINE_COLUMNS"
set -l addargs "$addargs --renderer-arg=mode=\$fish_bind_mode" set -l addargs "$addargs --renderer-arg=mode=\$fish_bind_mode"
@ -50,21 +50,21 @@ function powerline-setup
set -l promptside set -l promptside
set -l rpromptpast set -l rpromptpast
set -l columnsexpr set -l columnsexpr
if test -z "$POWERLINE_NO_FISH_ABOVE$POWERLINE_NO_SHELL_ABOVE" if begin set -q POWERLINE_NO_FISH_ABOVE; or set -q POWERLINE_NO_SHELL_ABOVE; end
set promptside aboveleft
set rpromptpast 'echo -n " "'
set columnsexpr '(math (_powerline_columns) - 1)'
else
set promptside left set promptside left
set rpromptpast set rpromptpast
set columnsexpr '(_powerline_columns)' set columnsexpr '(_powerline_columns)'
else
set promptside aboveleft
set rpromptpast 'echo -n " "'
set columnsexpr '(math (_powerline_columns) - 1)'
end end
echo " echo "
function fish_prompt function fish_prompt
env \$POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell $promptside $addargs eval \$POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell $promptside $addargs
end end
function fish_right_prompt function fish_right_prompt
env \$POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell right $addargs eval \$POWERLINE_COMMAND $POWERLINE_COMMAND_ARGS shell right $addargs
$rpromptpast $rpromptpast
end end
function fish_mode_prompt function fish_mode_prompt
@ -78,15 +78,15 @@ function powerline-setup
_powerline_set_default_mode _powerline_set_default_mode
_powerline_update _powerline_update
end end
if env $POWERLINE_CONFIG_COMMAND shell --shell=fish uses tmux if eval $POWERLINE_CONFIG_COMMAND shell --shell=fish uses tmux
if test -n "$TMUX" if set -q TMUX
if tmux refresh -S ^/dev/null if tmux refresh -S ^/dev/null
set -g _POWERLINE_TMUX "$TMUX" set -g _POWERLINE_TMUX "$TMUX"
function _powerline_tmux_pane function _powerline_tmux_pane
if test -z "$TMUX_PANE" if set -q TMUX_PANE
env TMUX="$_POWERLINE_TMUX" tmux display -p "#D" | tr -d ' %'
else
echo "$TMUX_PANE" | tr -d ' %' echo "$TMUX_PANE" | tr -d ' %'
else
env TMUX="$_POWERLINE_TMUX" tmux display -p "#D" | tr -d ' %'
end end
end end
function _powerline_tmux_setenv function _powerline_tmux_setenv