2023-11-09 03:57:36 +00:00
|
|
|
#! /usr/bin/env bash
|
2024-04-30 03:23:19 +00:00
|
|
|
# shellcheck disable=SC2034,SC1090
|
|
|
|
# SC2034 variables appear unsued. export if used externally
|
|
|
|
# - uneeded, as this checked whether script is sourced
|
|
|
|
# SC1090 Can't follow non-constant source
|
2023-11-09 03:57:36 +00:00
|
|
|
|
2024-04-30 03:23:19 +00:00
|
|
|
# Helper function
|
|
|
|
is_sourced() {
|
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
|
|
|
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
|
|
|
|
else # Add additional POSIX-compatible shell names here, if needed.
|
|
|
|
case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
|
|
|
|
fi
|
|
|
|
return 1; # NOT sourced.
|
|
|
|
}
|
|
|
|
|
|
|
|
BASE_0=${BASE_0:-$0}
|
|
|
|
BASE_SHELL=$(basename "$SHELL")
|
2023-11-09 03:57:36 +00:00
|
|
|
|
|
|
|
if [[ "$1" == "--force" ]]; then
|
|
|
|
[[ -e ~/.local/bin/fzf ]] && rm ~/.local/bin/fzf
|
|
|
|
[[ -e ~/.local/share/lib/fzf ]] && rm -fR ~/.local/share/lib/fzf
|
|
|
|
unset fzf
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$(type -t fzf)" || ! -e "$(type -p fzf)" ]]; then
|
2023-11-09 04:05:04 +00:00
|
|
|
curl -sS https://webi.sh/fzf | bash >&2
|
2023-11-09 03:57:36 +00:00
|
|
|
|
2024-04-30 03:23:19 +00:00
|
|
|
# shellcheck disable=SC2016 # $ inside single quotes is intentional
|
2023-11-09 03:57:36 +00:00
|
|
|
printf '%s\n' \
|
|
|
|
'Run the following and then try again:' \
|
|
|
|
' exec $SHELL -l' \
|
2023-11-09 04:05:04 +00:00
|
|
|
'' >&2
|
2024-04-30 03:23:19 +00:00
|
|
|
elif is_sourced; then
|
2023-11-09 03:57:36 +00:00
|
|
|
|
|
|
|
FZF_CTRL_T_COMMAND="command find -L . -xdev -mindepth 1 \\( \
|
|
|
|
-path '*/\\.*' \
|
|
|
|
-xdev \
|
|
|
|
-o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \
|
|
|
|
\\) -prune \
|
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
|
|
|
-o -type l -print 2> /dev/null | cut -b3- \
|
|
|
|
"
|
|
|
|
|
2024-04-30 03:23:19 +00:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
# variable appears unsued. export if used externally
|
|
|
|
# - uneeded, as script is sourced
|
2023-11-09 03:57:36 +00:00
|
|
|
FZF_ALT_C_COMMAND="command find -L . -xdev -mindepth 1 \\( \
|
|
|
|
-path '*/\\.*' \
|
|
|
|
-xdev \
|
|
|
|
-o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \
|
|
|
|
\\) -prune \
|
|
|
|
-o -type d
|
|
|
|
-print 2> /dev/null | cut -b3- \
|
|
|
|
"
|
|
|
|
|
|
|
|
SRCPATH="$HOME/.local/share/lib/fzf"
|
|
|
|
mkdir -p "$SRCPATH"
|
|
|
|
source_code_from() {
|
|
|
|
local SRCCODE="$SRCPATH/${1}"
|
|
|
|
[[ -r "$SRCCODE" ]] \
|
|
|
|
|| curl -sSLo "$SRCCODE" \
|
|
|
|
"https://raw.githubusercontent.com/junegunn/fzf/master/shell/${1}" \
|
|
|
|
&& cat "$SRCCODE"
|
|
|
|
}
|
|
|
|
. <( source_code_from key-bindings.bash )
|
|
|
|
. <( source_code_from completion.bash )
|
|
|
|
unset SRCPATH
|
|
|
|
elif [[ "$1" == '-' ]]; then
|
|
|
|
cat "${BASH_SOURCE[0]}"
|
|
|
|
else
|
|
|
|
SCRIPT_NAME="$BASE_0"
|
|
|
|
printf '%s\n' \
|
|
|
|
"It seems $SCRIPT_NAME was invoked as a script. It should be sourced instead." \
|
|
|
|
'The easiest way is to call it like this:' \
|
|
|
|
" $ . <( $SCRIPT_NAME - ) # Note the '-' after the script's name" \
|
|
|
|
''
|
|
|
|
fi
|