m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-08 11:23:47 -05:00

Apply shfmt to bash script files (make fmt)

This commit is contained in:
Junegunn Choi
2025-09-24 22:09:37 +09:00
parent f0c4ee4047
commit e8cb315419
11 changed files with 207 additions and 203 deletions

View File

@@ -4,7 +4,7 @@ root = true
indent_style = space indent_style = space
indent_size = 2 indent_size = 2
simplify = true simplify = true
binary_next_line = true binary_next_line = false
switch_case_indent = true switch_case_indent = true
space_redirects = true space_redirects = true
function_next_line = false function_next_line = false
@@ -14,7 +14,7 @@ function_next_line = false
indent_style = space indent_style = space
indent_size = 2 indent_size = 2
simplify = true simplify = true
binary_next_line = true binary_next_line = false
switch_case_indent = true switch_case_indent = true
space_redirects = true space_redirects = true
function_next_line = false function_next_line = false

View File

@@ -49,9 +49,9 @@ if [[ ! $type =~ image/ ]]; then
fi fi
dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES} dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}
if [[ $dim = x ]]; then if [[ $dim == x ]]; then
dim=$(stty size < /dev/tty | awk '{print $2 "x" $1}') dim=$(stty size < /dev/tty | awk '{print $2 "x" $1}')
elif ! [[ $KITTY_WINDOW_ID ]] && (( FZF_PREVIEW_TOP + FZF_PREVIEW_LINES == $(stty size < /dev/tty | awk '{print $1}') )); then elif ! [[ $KITTY_WINDOW_ID ]] && ((FZF_PREVIEW_TOP + FZF_PREVIEW_LINES == $(stty size < /dev/tty | awk '{print $1}'))); then
# Avoid scrolling issue when the Sixel image touches the bottom of the screen # Avoid scrolling issue when the Sixel image touches the bottom of the screen
# * https://github.com/junegunn/fzf/issues/2544 # * https://github.com/junegunn/fzf/issues/2544
dim=${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES - 1)) dim=${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES - 1))

View File

@@ -8,7 +8,7 @@ fail() {
} }
fzf="$(command which fzf)" || fzf="$(dirname "$0")/fzf" fzf="$(command which fzf)" || fzf="$(dirname "$0")/fzf"
[[ -x "$fzf" ]] || fail 'fzf executable not found' [[ -x $fzf ]] || fail 'fzf executable not found'
args=() args=()
opt="" opt=""
@@ -16,8 +16,8 @@ skip=""
swap="" swap=""
close="" close=""
term="" term=""
[[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}") [[ -n $LINES ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}")
[[ -n "$COLUMNS" ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}") [[ -n $COLUMNS ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}")
tmux_version=$(tmux -V | sed 's/[^0-9.]//g') tmux_version=$(tmux -V | sed 's/[^0-9.]//g')
tmux_32=$(awk '{print ($1 >= 3.2)}' <<< "$tmux_version" 2> /dev/null || bc -l <<< "$tmux_version >= 3.2") tmux_32=$(awk '{print ($1 >= 3.2)}' <<< "$tmux_version" 2> /dev/null || bc -l <<< "$tmux_version >= 3.2")
@@ -47,7 +47,7 @@ help() {
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
arg="$1" arg="$1"
shift shift
[[ -z "$skip" ]] && case "$arg" in [[ -z $skip ]] && case "$arg" in
-) -)
term=1 term=1
;; ;;
@@ -58,19 +58,19 @@ while [[ $# -gt 0 ]]; do
echo "fzf-tmux (with fzf $("$fzf" --version))" echo "fzf-tmux (with fzf $("$fzf" --version))"
exit exit
;; ;;
-p*|-w*|-h*|-x*|-y*|-d*|-u*|-r*|-l*) -p* | -w* | -h* | -x* | -y* | -d* | -u* | -r* | -l*)
if [[ "$arg" =~ ^-[pwhxy] ]]; then if [[ $arg =~ ^-[pwhxy] ]]; then
[[ "$opt" =~ "-E" ]] || opt="-E" [[ $opt =~ "-E" ]] || opt="-E"
elif [[ "$arg" =~ ^.[lr] ]]; then elif [[ $arg =~ ^.[lr] ]]; then
opt="-h" opt="-h"
if [[ "$arg" =~ ^.l ]]; then if [[ $arg =~ ^.l ]]; then
opt="$opt -d" opt="$opt -d"
swap="; swap-pane -D ; select-pane -L" swap="; swap-pane -D ; select-pane -L"
close="; tmux swap-pane -D" close="; tmux swap-pane -D"
fi fi
else else
opt="" opt=""
if [[ "$arg" =~ ^.u ]]; then if [[ $arg =~ ^.u ]]; then
opt="$opt -d" opt="$opt -d"
swap="; swap-pane -D ; select-pane -U" swap="; swap-pane -D ; select-pane -U"
close="; tmux swap-pane -D" close="; tmux swap-pane -D"
@@ -79,7 +79,7 @@ while [[ $# -gt 0 ]]; do
if [[ ${#arg} -gt 2 ]]; then if [[ ${#arg} -gt 2 ]]; then
size="${arg:2}" size="${arg:2}"
else else
if [[ "$1" =~ ^[0-9%,]+$ ]] || [[ "$1" =~ ^[A-Z]$ ]]; then if [[ $1 =~ ^[0-9%,]+$ ]] || [[ $1 =~ ^[A-Z]$ ]]; then
size="$1" size="$1"
shift shift
else else
@@ -87,37 +87,37 @@ while [[ $# -gt 0 ]]; do
fi fi
fi fi
if [[ "$arg" =~ ^-p ]]; then if [[ $arg =~ ^-p ]]; then
if [[ -n "$size" ]]; then if [[ -n $size ]]; then
w=${size%%,*} w=${size%%,*}
h=${size##*,} h=${size##*,}
opt="$opt -w$w -h$h" opt="$opt -w$w -h$h"
fi fi
elif [[ "$arg" =~ ^-[whxy] ]]; then elif [[ $arg =~ ^-[whxy] ]]; then
opt="$opt ${arg:0:2}$size" opt="$opt ${arg:0:2}$size"
elif [[ "$size" =~ %$ ]]; then elif [[ $size =~ %$ ]]; then
size=${size:0:((${#size}-1))} size=${size:0:${#size}-1}
if [[ $tmux_32 = 1 ]]; then if [[ $tmux_32 == 1 ]]; then
if [[ -n "$swap" ]]; then if [[ -n $swap ]]; then
opt="$opt -l $(( 100 - size ))%" opt="$opt -l $((100 - size))%"
else else
opt="$opt -l $size%" opt="$opt -l $size%"
fi fi
else else
if [[ -n "$swap" ]]; then if [[ -n $swap ]]; then
opt="$opt -p $(( 100 - size ))" opt="$opt -p $((100 - size))"
else else
opt="$opt -p $size" opt="$opt -p $size"
fi fi
fi fi
else else
if [[ -n "$swap" ]]; then if [[ -n $swap ]]; then
if [[ "$arg" =~ ^.l ]]; then if [[ $arg =~ ^.l ]]; then
max=$columns max=$columns
else else
max=$lines max=$lines
fi fi
size=$(( max - size )) size=$((max - size))
[[ $size -lt 0 ]] && size=0 [[ $size -lt 0 ]] && size=0
opt="$opt -l $size" opt="$opt -l $size"
else else
@@ -135,10 +135,10 @@ while [[ $# -gt 0 ]]; do
args+=("$arg") args+=("$arg")
;; ;;
esac esac
[[ -n "$skip" ]] && args+=("$arg") [[ -n $skip ]] && args+=("$arg")
done done
if [[ -z "$TMUX" ]]; then if [[ -z $TMUX ]]; then
"$fzf" "${args[@]}" "$fzf" "${args[@]}"
exit $? exit $?
fi fi
@@ -149,7 +149,7 @@ fi
args=("${args[@]}" "--no-height" "--bind=ctrl-z:ignore" "--no-tmux") args=("${args[@]}" "--no-height" "--bind=ctrl-z:ignore" "--no-tmux")
# Handle zoomed tmux pane without popup options by moving it to a temp window # Handle zoomed tmux pane without popup options by moving it to a temp window
if [[ ! "$opt" =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then if [[ ! $opt =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then
zoomed_without_popup=1 zoomed_without_popup=1
original_window=$(tmux display-message -p "#{window_id}") original_window=$(tmux display-message -p "#{window_id}")
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'") tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
@@ -165,22 +165,22 @@ fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"
fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id" fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id" fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
if tmux_win_opts=$(tmux show-options -p remain-on-exit \; show-options -p synchronize-panes 2> /dev/null); then if tmux_win_opts=$(tmux show-options -p remain-on-exit \; show-options -p synchronize-panes 2> /dev/null); then
tmux_win_opts=( $(sed '/ off/d; s/synchronize-panes/set-option -p synchronize-panes/; s/remain-on-exit/set-option -p remain-on-exit/; s/$/ \\;/' <<< "$tmux_win_opts") ) tmux_win_opts=($(sed '/ off/d; s/synchronize-panes/set-option -p synchronize-panes/; s/remain-on-exit/set-option -p remain-on-exit/; s/$/ \\;/' <<< "$tmux_win_opts"))
tmux_off_opts='; set-option -p synchronize-panes off ; set-option -p remain-on-exit off' tmux_off_opts='; set-option -p synchronize-panes off ; set-option -p remain-on-exit off'
else else
tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') ) tmux_win_opts=($(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/'))
tmux_off_opts='; set-window-option synchronize-panes off ; set-window-option remain-on-exit off' tmux_off_opts='; set-window-option synchronize-panes off ; set-window-option remain-on-exit off'
fi fi
cleanup() { cleanup() {
\rm -f $argsf $fifo1 $fifo2 $fifo3 \rm -f $argsf $fifo1 $fifo2 $fifo3
# Restore tmux window options # Restore tmux window options
if [[ "${#tmux_win_opts[@]}" -gt 1 ]]; then if [[ ${#tmux_win_opts[@]} -gt 1 ]]; then
eval "tmux ${tmux_win_opts[*]}" eval "tmux ${tmux_win_opts[*]}"
fi fi
# Remove temp window if we were zoomed without popup options # Remove temp window if we were zoomed without popup options
if [[ -n "$zoomed_without_popup" ]]; then if [[ -n $zoomed_without_popup ]]; then
tmux display-message -p "#{window_id}" > /dev/null tmux display-message -p "#{window_id}" > /dev/null
tmux swap-pane -t $original_window \; \ tmux swap-pane -t $original_window \; \
select-window -t $original_window \; \ select-window -t $original_window \; \
@@ -197,10 +197,10 @@ trap 'cleanup 1' SIGUSR1
trap 'cleanup' EXIT trap 'cleanup' EXIT
envs="export TERM=$TERM " envs="export TERM=$TERM "
if [[ "$opt" =~ "-E" ]]; then if [[ $opt =~ "-E" ]]; then
if [[ $tmux_version = 3.2 ]]; then if [[ $tmux_version == 3.2 ]]; then
FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS" FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS"
elif [[ $tmux_32 = 1 ]]; then elif [[ $tmux_32 == 1 ]]; then
FZF_DEFAULT_OPTS="--border $FZF_DEFAULT_OPTS" FZF_DEFAULT_OPTS="--border $FZF_DEFAULT_OPTS"
opt="-B $opt" opt="-B $opt"
else else
@@ -211,8 +211,8 @@ fi
envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")" envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"
envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")" envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
envs="$envs FZF_DEFAULT_OPTS_FILE=$(printf %q "$FZF_DEFAULT_OPTS_FILE")" envs="$envs FZF_DEFAULT_OPTS_FILE=$(printf %q "$FZF_DEFAULT_OPTS_FILE")"
[[ -n "$RUNEWIDTH_EASTASIAN" ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")" [[ -n $RUNEWIDTH_EASTASIAN ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")"
[[ -n "$BAT_THEME" ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")" [[ -n $BAT_THEME ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")"
echo "$envs;" > "$argsf" echo "$envs;" > "$argsf"
# Build arguments to fzf # Build arguments to fzf
@@ -224,9 +224,9 @@ close="; trap - EXIT SIGINT SIGTERM $close"
export TMUX=$(cut -d , -f 1,2 <<< "$TMUX") export TMUX=$(cut -d , -f 1,2 <<< "$TMUX")
mkfifo -m o+w $fifo2 mkfifo -m o+w $fifo2
if [[ "$opt" =~ "-E" ]]; then if [[ $opt =~ "-E" ]]; then
cat $fifo2 & cat $fifo2 &
if [[ -n "$term" ]] || [[ -t 0 ]]; then if [[ -n $term ]] || [[ -t 0 ]]; then
cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf
else else
mkfifo $fifo1 mkfifo $fifo1
@@ -239,7 +239,7 @@ if [[ "$opt" =~ "-E" ]]; then
fi fi
mkfifo -m o+w $fifo3 mkfifo -m o+w $fifo3
if [[ -n "$term" ]] || [[ -t 0 ]]; then if [[ -n $term ]] || [[ -t 0 ]]; then
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf
else else
mkfifo $fifo1 mkfifo $fifo1
@@ -249,6 +249,9 @@ fi
tmux \ tmux \
split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \ split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \
$tmux_off_opts \ $tmux_off_opts \
> /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; } > /dev/null 2>&1 || {
"$fzf" "${args[@]}"
exit $?
}
cat $fifo2 cat $fifo2
exit "$(cat $fifo3)" exit "$(cat $fifo3)"

26
install
View File

@@ -104,7 +104,7 @@ check_binary() {
link_fzf_in_path() { link_fzf_in_path() {
if which_fzf="$(command -v fzf)"; then if which_fzf="$(command -v fzf)"; then
echo " - Found in \$PATH" echo ' - Found in $PATH'
echo " - Creating symlink: bin/fzf -> $which_fzf" echo " - Creating symlink: bin/fzf -> $which_fzf"
(cd "$fzf_base"/bin && rm -f fzf && ln -sf "$which_fzf" fzf) (cd "$fzf_base"/bin && rm -f fzf && ln -sf "$which_fzf" fzf)
check_binary && return check_binary && return
@@ -164,7 +164,7 @@ download() {
} }
# Try to download binary executable # Try to download binary executable
archi=$(uname -smo 2>/dev/null || uname -sm) archi=$(uname -smo 2> /dev/null || uname -sm)
binary_available=1 binary_available=1
binary_error="" binary_error=""
case "$archi" in case "$archi" in
@@ -215,7 +215,7 @@ if [ -n "$binary_error" ]; then
fi fi
fi fi
[[ "$*" =~ "--bin" ]] && exit 0 [[ $* =~ "--bin" ]] && exit 0
for s in $shells; do for s in $shells; do
if ! command -v "$s" > /dev/null; then if ! command -v "$s" > /dev/null; then
@@ -242,7 +242,7 @@ fi
echo echo
for shell in $shells; do for shell in $shells; do
[[ "$shell" = fish ]] && continue [[ $shell == fish ]] && continue
src=${prefix_expand}.${shell} src=${prefix_expand}.${shell}
echo -n "Generate $src ... " echo -n "Generate $src ... "
@@ -266,7 +266,7 @@ fi
EOF EOF
if [[ $auto_completion -eq 1 ]] && [[ $key_bindings -eq 1 ]]; then if [[ $auto_completion -eq 1 ]] && [[ $key_bindings -eq 1 ]]; then
if [[ "$shell" = zsh ]]; then if [[ $shell == zsh ]]; then
echo "source <(fzf --$shell)" >> "$src" echo "source <(fzf --$shell)" >> "$src"
else else
echo "eval \"\$(fzf --$shell)\"" >> "$src" echo "eval \"\$(fzf --$shell)\"" >> "$src"
@@ -286,7 +286,7 @@ EOF
done done
# fish # fish
if [[ "$shells" =~ fish ]]; then if [[ $shells =~ fish ]]; then
echo -n "Update fish_user_paths ... " echo -n "Update fish_user_paths ... "
fish << EOF fish << EOF
echo \$fish_user_paths | \grep "$fzf_base"/bin > /dev/null echo \$fish_user_paths | \grep "$fzf_base"/bin > /dev/null
@@ -318,7 +318,7 @@ append_line() {
sed 's/^/ Line /' <<< "$lines" sed 's/^/ Line /' <<< "$lines"
update=0 update=0
if ! \grep -qv "^[0-9]*:[[:space:]]*#" <<< "$lines" ; then if ! \grep -qv "^[0-9]*:[[:space:]]*#" <<< "$lines"; then
echo " - But they all seem to be commented" echo " - But they all seem to be commented"
ask " - Continue modifying $file?" ask " - Continue modifying $file?"
update=$? update=$?
@@ -356,12 +356,12 @@ if [ $update_config -eq 2 ]; then
fi fi
echo echo
for shell in $shells; do for shell in $shells; do
[[ "$shell" = fish ]] && continue [[ $shell == fish ]] && continue
[ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc [ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc
append_line $update_config "[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" "$dest" "${prefix}.${shell}" append_line $update_config "[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" "$dest" "${prefix}.${shell}"
done done
if [ $key_bindings -eq 1 ] && [[ "$shells" =~ fish ]]; then if [ $key_bindings -eq 1 ] && [[ $shells =~ fish ]]; then
bind_file="${fish_dir}/functions/fish_user_key_bindings.fish" bind_file="${fish_dir}/functions/fish_user_key_bindings.fish"
if [ ! -e "$bind_file" ]; then if [ ! -e "$bind_file" ]; then
mkdir -p "${fish_dir}/functions" mkdir -p "${fish_dir}/functions"
@@ -386,13 +386,13 @@ fi
if [ $update_config -eq 1 ]; then if [ $update_config -eq 1 ]; then
echo 'Finished. Restart your shell or reload config file.' echo 'Finished. Restart your shell or reload config file.'
if [[ "$shells" =~ bash ]]; then if [[ $shells =~ bash ]]; then
echo -n ' source ~/.bashrc # bash' echo -n ' source ~/.bashrc # bash'
[[ "$archi" =~ Darwin ]] && echo -n ' (.bashrc should be loaded from .bash_profile)' [[ $archi =~ Darwin ]] && echo -n ' (.bashrc should be loaded from .bash_profile)'
echo echo
fi fi
[[ "$shells" =~ zsh ]] && echo " source ${ZDOTDIR:-~}/.zshrc # zsh" [[ $shells =~ zsh ]] && echo " source ${ZDOTDIR:-~}/.zshrc # zsh"
[[ "$shells" =~ fish ]] && [ $key_bindings -eq 1 ] && echo ' fzf_key_bindings # fish' [[ $shells =~ fish ]] && [ $key_bindings -eq 1 ] && echo ' fzf_key_bindings # fish'
echo echo
echo 'Use uninstall script to remove fzf.' echo 'Use uninstall script to remove fzf.'
echo echo

View File

@@ -1,4 +1,3 @@
__fzf_defaults() { __fzf_defaults() {
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS # $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS # $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
@@ -22,12 +21,12 @@ __fzf_exec_awk() {
# modern point of view. To use a standard-conforming version in Solaris, # modern point of view. To use a standard-conforming version in Solaris,
# one needs to explicitly use /usr/xpg4/bin/awk. # one needs to explicitly use /usr/xpg4/bin/awk.
__fzf_awk=/usr/xpg4/bin/awk __fzf_awk=/usr/xpg4/bin/awk
elif command -v mawk >/dev/null 2>&1; then elif command -v mawk > /dev/null 2>&1; then
# choose the faster mawk if: it's installed && build date >= 20230322 && # choose the faster mawk if: it's installed && build date >= 20230322 &&
# version >= 1.3.4 # version >= 1.3.4
local n x y z d local n x y z d
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
fi fi
fi fi
# Note: macOS awk has a quirk that it stops processing at all when it sees # Note: macOS awk has a quirk that it stops processing at all when it sees

View File

@@ -48,10 +48,10 @@ __fzf_exec_awk() {
__fzf_awk=awk __fzf_awk=awk
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
__fzf_awk=/usr/xpg4/bin/awk __fzf_awk=/usr/xpg4/bin/awk
elif command -v mawk >/dev/null 2>&1; then elif command -v mawk > /dev/null 2>&1; then
local n x y z d local n x y z d
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
fi fi
fi fi
LC_ALL=C exec "$__fzf_awk" "$@" LC_ALL=C exec "$__fzf_awk" "$@"
@@ -59,9 +59,9 @@ __fzf_exec_awk() {
#----END INCLUDE #----END INCLUDE
__fzf_comprun() { __fzf_comprun() {
if [[ "$(type -t _fzf_comprun 2>&1)" = function ]]; then if [[ "$(type -t _fzf_comprun 2>&1)" == function ]]; then
_fzf_comprun "$@" _fzf_comprun "$@"
elif [[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; }; then elif [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; }; then
shift shift
fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@" fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"
else else
@@ -73,13 +73,13 @@ __fzf_comprun() {
__fzf_orig_completion() { __fzf_orig_completion() {
local l comp f cmd local l comp f cmd
while read -r l; do while read -r l; do
if [[ "$l" =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then if [[ $l =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then
comp="${BASH_REMATCH[1]}" comp="${BASH_REMATCH[1]}"
f="${BASH_REMATCH[2]}" f="${BASH_REMATCH[2]}"
cmd="${BASH_REMATCH[3]}" cmd="${BASH_REMATCH[3]}"
[[ "$f" = _fzf_* ]] && continue [[ $f == _fzf_* ]] && continue
printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}" printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"
if [[ "$l" = *" -o nospace "* ]] && [[ ! "${__fzf_nospace_commands-}" = *" $cmd "* ]]; then if [[ $l == *" -o nospace "* ]] && [[ ${__fzf_nospace_commands-} != *" $cmd "* ]]; then
__fzf_nospace_commands="${__fzf_nospace_commands-} $cmd " __fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "
fi fi
fi fi
@@ -115,7 +115,7 @@ _fzf_opts_completion() {
local cur prev opts local cur prev opts
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD - 1]}"
opts=" opts="
+c --no-color +c --no-color
+i --no-ignore-case +i --no-ignore-case
@@ -199,27 +199,27 @@ _fzf_opts_completion() {
case "${prev}" in case "${prev}" in
--scheme) --scheme)
COMPREPLY=( $(compgen -W "default path history" -- "$cur") ) COMPREPLY=($(compgen -W "default path history" -- "$cur"))
return 0 return 0
;; ;;
--tiebreak) --tiebreak)
COMPREPLY=( $(compgen -W "length chunk begin end index" -- "$cur") ) COMPREPLY=($(compgen -W "length chunk begin end index" -- "$cur"))
return 0 return 0
;; ;;
--color) --color)
COMPREPLY=( $(compgen -W "dark light 16 bw no" -- "$cur") ) COMPREPLY=($(compgen -W "dark light 16 bw no" -- "$cur"))
return 0 return 0
;; ;;
--layout) --layout)
COMPREPLY=( $(compgen -W "default reverse reverse-list" -- "$cur") ) COMPREPLY=($(compgen -W "default reverse reverse-list" -- "$cur"))
return 0 return 0
;; ;;
--info) --info)
COMPREPLY=( $(compgen -W "default right hidden inline inline-right" -- "$cur") ) COMPREPLY=($(compgen -W "default right hidden inline inline-right" -- "$cur"))
return 0 return 0
;; ;;
--preview-window) --preview-window)
COMPREPLY=( $(compgen -W " COMPREPLY=($(compgen -W "
default default
hidden hidden
nohidden nohidden
@@ -245,21 +245,21 @@ _fzf_opts_completion() {
border-left border-left
border-right border-right
follow follow
nofollow" -- "$cur") ) nofollow" -- "$cur"))
return 0 return 0
;; ;;
--border) --border)
COMPREPLY=( $(compgen -W "rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur") ) COMPREPLY=($(compgen -W "rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur"))
return 0 return 0
;; ;;
--border-label-pos|--preview-label-pos) --border-label-pos | --preview-label-pos)
COMPREPLY=( $(compgen -W "center bottom top" -- "$cur") ) COMPREPLY=($(compgen -W "center bottom top" -- "$cur"))
return 0 return 0
;; ;;
esac esac
if [[ "$cur" =~ ^-|\+ ]]; then if [[ $cur =~ ^-|\+ ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- "$cur") ) COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
return 0 return 0
fi fi
@@ -273,7 +273,7 @@ _fzf_handle_dynamic_completion() {
orig_cmd="$1" orig_cmd="$1"
if __fzf_orig_completion_get_orig_func "$cmd"; then if __fzf_orig_completion_get_orig_func "$cmd"; then
"$REPLY" "$@" "$REPLY" "$@"
elif [[ -n "${_fzf_completion_loader-}" ]]; then elif [[ -n ${_fzf_completion_loader-} ]]; then
orig_complete=$(complete -p "$orig_cmd" 2> /dev/null) orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)
$_fzf_completion_loader "$@" $_fzf_completion_loader "$@"
ret=$? ret=$?
@@ -287,7 +287,7 @@ _fzf_handle_dynamic_completion() {
__fzf_orig_completion_instantiate "$cmd" "${BASH_REMATCH[1]}" && __fzf_orig_completion_instantiate "$cmd" "${BASH_REMATCH[1]}" &&
orig_complete=$REPLY orig_complete=$REPLY
if [[ "${__fzf_nospace_commands-}" = *" $orig_cmd "* ]]; then if [[ ${__fzf_nospace_commands-} == *" $orig_cmd "* ]]; then
eval "${orig_complete/ -F / -o nospace -F }" eval "${orig_complete/ -F / -o nospace -F }"
else else
eval "$orig_complete" eval "$orig_complete"
@@ -307,18 +307,18 @@ __fzf_generic_path_completion() {
COMPREPLY=() COMPREPLY=()
trigger=${FZF_COMPLETION_TRIGGER-'**'} trigger=${FZF_COMPLETION_TRIGGER-'**'}
[[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}" [[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then
base=${cur:0:${#cur}-${#trigger}} base=${cur:0:${#cur}-${#trigger}}
eval "base=$base" 2> /dev/null || return eval "base=$base" 2> /dev/null || return
dir= dir=
[[ $base = *"/"* ]] && dir="$base" [[ $base == *"/"* ]] && dir="$base"
while true; do while true; do
if [[ -z "$dir" ]] || [[ -d "$dir" ]]; then if [[ -z $dir ]] || [[ -d $dir ]]; then
leftover=${base/#"$dir"} leftover=${base/#"$dir"/}
leftover=${leftover/#\/} leftover=${leftover/#\//}
[[ -z "$dir" ]] && dir='.' [[ -z $dir ]] && dir='.'
[[ "$dir" != "/" ]] && dir="${dir/%\//}" [[ $dir != "/" ]] && dir="${dir/%\//}"
matches=$( matches=$(
export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2") export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")
unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
@@ -338,11 +338,11 @@ __fzf_generic_path_completion() {
done done
) )
matches=${matches% } matches=${matches% }
[[ -z "$3" ]] && [[ "${__fzf_nospace_commands-}" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches " [[ -z $3 ]] && [[ ${__fzf_nospace_commands-} == *" ${COMP_WORDS[0]} "* ]] && matches="$matches "
if [[ -n "$matches" ]]; then if [[ -n $matches ]]; then
COMPREPLY=( "$matches" ) COMPREPLY=("$matches")
else else
COMPREPLY=( "$cur" ) COMPREPLY=("$cur")
fi fi
# To redraw line after fzf closes (printf '\e[5n') # To redraw line after fzf closes (printf '\e[5n')
bind '"\e[0n": redraw-current-line' 2> /dev/null bind '"\e[0n": redraw-current-line' 2> /dev/null
@@ -350,7 +350,7 @@ __fzf_generic_path_completion() {
return 0 return 0
fi fi
dir=$(command dirname "$dir") dir=$(command dirname "$dir")
[[ "$dir" =~ /$ ]] || dir="$dir"/ [[ $dir =~ /$ ]] || dir="$dir"/
done done
else else
shift shift
@@ -366,15 +366,15 @@ _fzf_complete() {
args=("$@") args=("$@")
sep= sep=
for i in "${!args[@]}"; do for i in "${!args[@]}"; do
if [[ "${args[$i]}" = -- ]]; then if [[ ${args[$i]} == -- ]]; then
sep=$i sep=$i
break break
fi fi
done done
if [[ -n "$sep" ]]; then if [[ -n $sep ]]; then
str_arg= str_arg=
rest=("${args[@]:$((sep + 1)):${#args[@]}}") rest=("${args[@]:$((sep + 1)):${#args[@]}}")
args=("${args[@]:0:$sep}") args=("${args[@]:0:sep}")
else else
str_arg=$1 str_arg=$1
args=() args=()
@@ -389,15 +389,16 @@ _fzf_complete() {
trigger=${FZF_COMPLETION_TRIGGER-'**'} trigger=${FZF_COMPLETION_TRIGGER-'**'}
cmd="${COMP_WORDS[0]}" cmd="${COMP_WORDS[0]}"
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then if [[ $cur == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then
cur=${cur:0:${#cur}-${#trigger}} cur=${cur:0:${#cur}-${#trigger}}
selected=$( selected=$(
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \ FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \
FZF_DEFAULT_OPTS_FILE='' \ FZF_DEFAULT_OPTS_FILE='' \
__fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | eval "$post" | command tr '\n' ' ') __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | eval "$post" | command tr '\n' ' '
)
selected=${selected% } # Strip trailing space not to repeat "-o nospace" selected=${selected% } # Strip trailing space not to repeat "-o nospace"
if [[ -n "$selected" ]]; then if [[ -n $selected ]]; then
COMPREPLY=("$selected") COMPREPLY=("$selected")
else else
COMPREPLY=("$cur") COMPREPLY=("$cur")
@@ -541,12 +542,12 @@ _fzf_host_completion() {
# > and the third argument ($3) is the word preceding the word being completed on the current command line. # > and the third argument ($3) is the word preceding the word being completed on the current command line.
_fzf_complete_ssh() { _fzf_complete_ssh() {
case $3 in case $3 in
-i|-F|-E) -i | -F | -E)
_fzf_path_completion "$@" _fzf_path_completion "$@"
;; ;;
*) *)
local user= local user=
[[ "$2" =~ '@' ]] && user="${2%%@*}@" [[ $2 =~ '@' ]] && user="${2%%@*}@"
_fzf_complete +m -- "$@" < <(__fzf_list_hosts | __fzf_exec_awk -v user="$user" '{print user $0}') _fzf_complete +m -- "$@" < <(__fzf_list_hosts | __fzf_exec_awk -v user="$user" '{print user $0}')
;; ;;
esac esac

View File

@@ -112,10 +112,10 @@ __fzf_exec_awk() {
__fzf_awk=awk __fzf_awk=awk
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
__fzf_awk=/usr/xpg4/bin/awk __fzf_awk=/usr/xpg4/bin/awk
elif command -v mawk >/dev/null 2>&1; then elif command -v mawk > /dev/null 2>&1; then
local n x y z d local n x y z d
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
fi fi
fi fi
LC_ALL=C exec "$__fzf_awk" "$@" LC_ALL=C exec "$__fzf_awk" "$@"

View File

@@ -34,10 +34,10 @@ __fzf_exec_awk() {
__fzf_awk=awk __fzf_awk=awk
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
__fzf_awk=/usr/xpg4/bin/awk __fzf_awk=/usr/xpg4/bin/awk
elif command -v mawk >/dev/null 2>&1; then elif command -v mawk > /dev/null 2>&1; then
local n x y z d local n x y z d
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
fi fi
fi fi
LC_ALL=C exec "$__fzf_awk" "$@" LC_ALL=C exec "$__fzf_awk" "$@"
@@ -54,14 +54,14 @@ __fzf_select__() {
} }
__fzfcmd() { __fzfcmd() {
[[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; } && [[ -n ${TMUX_PANE-} ]] && { [[ ${FZF_TMUX:-0} != 0 ]] || [[ -n ${FZF_TMUX_OPTS-} ]]; } &&
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf" echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
} }
fzf-file-widget() { fzf-file-widget() {
local selected="$(__fzf_select__ "$@")" local selected="$(__fzf_select__ "$@")"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}" READLINE_LINE="${READLINE_LINE:0:READLINE_POINT}$selected${READLINE_LINE:READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} )) READLINE_POINT=$((READLINE_POINT + ${#selected}))
} }
__fzf_cd__() { __fzf_cd__() {
@@ -85,7 +85,7 @@ if command -v perl > /dev/null; then
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE" FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"
) || return ) || return
READLINE_LINE=$(command perl -pe 's/^\d*\t//' <<< "$output") READLINE_LINE=$(command perl -pe 's/^\d*\t//' <<< "$output")
if [[ -z "$READLINE_POINT" ]]; then if [[ -z $READLINE_POINT ]]; then
echo "$READLINE_LINE" echo "$READLINE_LINE"
else else
READLINE_POINT=0x7fffffff READLINE_POINT=0x7fffffff
@@ -108,7 +108,7 @@ else # awk - fallback for POSIX systems
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE" FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"
) || return ) || return
READLINE_LINE=${output#*$'\t'} READLINE_LINE=${output#*$'\t'}
if [[ -z "$READLINE_POINT" ]]; then if [[ -z $READLINE_POINT ]]; then
echo "$READLINE_LINE" echo "$READLINE_LINE"
else else
READLINE_POINT=0x7fffffff READLINE_POINT=0x7fffffff
@@ -123,9 +123,9 @@ bind -m vi-command '"\C-z": emacs-editing-mode'
bind -m vi-insert '"\C-z": emacs-editing-mode' bind -m vi-insert '"\C-z": emacs-editing-mode'
bind -m emacs-standard '"\C-z": vi-editing-mode' bind -m emacs-standard '"\C-z": vi-editing-mode'
if (( BASH_VERSINFO[0] < 4 )); then if ((BASH_VERSINFO[0] < 4)); then
# CTRL-T - Paste the selected file path into the command line # CTRL-T - Paste the selected file path into the command line
if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; then
bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f\C-y\ey\C-_"' bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f\C-y\ey\C-_"'
bind -m vi-command '"\C-t": "\C-z\C-t\C-z"' bind -m vi-command '"\C-t": "\C-z\C-t\C-z"'
bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"' bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"'
@@ -137,7 +137,7 @@ if (( BASH_VERSINFO[0] < 4 )); then
bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"' bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"'
else else
# CTRL-T - Paste the selected file path into the command line # CTRL-T - Paste the selected file path into the command line
if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then if [[ ${FZF_CTRL_T_COMMAND-x} != "" ]]; then
bind -m emacs-standard -x '"\C-t": fzf-file-widget' bind -m emacs-standard -x '"\C-t": fzf-file-widget'
bind -m vi-command -x '"\C-t": fzf-file-widget' bind -m vi-command -x '"\C-t": fzf-file-widget'
bind -m vi-insert -x '"\C-t": fzf-file-widget' bind -m vi-insert -x '"\C-t": fzf-file-widget'
@@ -150,7 +150,7 @@ else
fi fi
# ALT-C - cd into the selected directory # ALT-C - cd into the selected directory
if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then if [[ ${FZF_ALT_C_COMMAND-x} != "" ]]; then
bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d\C-y\ey\C-_"' bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d\C-y\ey\C-_"'
bind -m vi-command '"\ec": "\C-z\ec\C-z"' bind -m vi-command '"\ec": "\C-z\ec\C-z"'
bind -m vi-insert '"\ec": "\C-z\ec\C-z"' bind -m vi-insert '"\ec": "\C-z\ec\C-z"'

View File

@@ -54,10 +54,10 @@ __fzf_exec_awk() {
__fzf_awk=awk __fzf_awk=awk
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
__fzf_awk=/usr/xpg4/bin/awk __fzf_awk=/usr/xpg4/bin/awk
elif command -v mawk >/dev/null 2>&1; then elif command -v mawk > /dev/null 2>&1; then
local n x y z d local n x y z d
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk
fi fi
fi fi
LC_ALL=C exec "$__fzf_awk" "$@" LC_ALL=C exec "$__fzf_awk" "$@"

View File

@@ -9,11 +9,12 @@ dir=${0%"${0##*/}"}
update() { update() {
{ {
sed -n '1,/^#----BEGIN INCLUDE common\.sh/p' "$1" sed -n '1,/^#----BEGIN INCLUDE common\.sh/p' "$1"
cat <<EOF cat << EOF
# NOTE: Do not directly edit this section, which is copied from "common.sh". # NOTE: Do not directly edit this section, which is copied from "common.sh".
# To modify it, one can edit "common.sh" and run "./update.sh" to apply # To modify it, one can edit "common.sh" and run "./update.sh" to apply
# the changes. See code comments in "common.sh" for the implementation details. # the changes. See code comments in "common.sh" for the implementation details.
EOF EOF
echo
grep -v '^[[:blank:]]*#' "$dir/common.sh" # remove code comments in common.sh grep -v '^[[:blank:]]*#' "$dir/common.sh" # remove code comments in common.sh
sed -n '/^#----END INCLUDE/,$p' "$1" sed -n '/^#----END INCLUDE/,$p' "$1"
} > "$1.part" } > "$1.part"

View File

@@ -64,7 +64,7 @@ remove_line() {
line_no=1 line_no=1
continue continue
fi fi
line_no=$(( $(sed 's/:.*//' <<< "$line") + line_no - 1 )) line_no=$(($(sed 's/:.*//' <<< "$line") + line_no - 1))
content=$(sed 's/^[0-9]*://' <<< "$line") content=$(sed 's/^[0-9]*://' <<< "$line")
match=1 match=1
echo " - Line #$line_no: $content" echo " - Line #$line_no: $content"
@@ -76,7 +76,7 @@ remove_line() {
echo " - Removed" echo " - Removed"
else else
echo " - Skipped" echo " - Skipped"
line_no=$(( line_no + 1 )) line_no=$((line_no + 1))
fi fi
done done
[ $match -eq 0 ] && echo " - Nothing found" [ $match -eq 0 ] && echo " - Nothing found"
@@ -109,6 +109,6 @@ if [ -d "${fish_dir}/functions" ]; then
fi fi
config_dir=$(dirname "$prefix_expand") config_dir=$(dirname "$prefix_expand")
if [[ "$xdg" = 1 ]] && [[ "$config_dir" = */fzf ]] && [[ -d "$config_dir" ]]; then if [[ $xdg == 1 ]] && [[ $config_dir == */fzf ]] && [[ -d $config_dir ]]; then
rmdir "$config_dir" rmdir "$config_dir"
fi fi