···11+# This is terribly complicated
22+# It's because:
33+# 1. bun run has to have dynamic completions
44+# 2. there are global options
55+# 3. bun {install add remove} gets special options
66+# 4. I don't know how to write fish completions well
77+# Contributions very welcome!!
88+99+function __fish__get_bun_bins
1010+ string split ' ' (bun getcompletes b)
1111+end
1212+1313+function __fish__get_bun_scripts
1414+ set -lx SHELL bash
1515+ set -lx MAX_DESCRIPTION_LEN 40
1616+ string trim (string split '\n' (string split '\t' (bun getcompletes z)))
1717+end
1818+1919+function __fish__get_bun_packages
2020+ if test (commandline -ct) != ""
2121+ set -lx SHELL fish
2222+ string split ' ' (bun getcompletes a (commandline -ct))
2323+ end
2424+end
2525+2626+function __history_completions
2727+ set -l tokens (commandline --current-process --tokenize)
2828+ history --prefix (commandline) | string replace -r \^$tokens[1]\\s\* "" | string replace -r \^$tokens[2]\\s\* "" | string split ' '
2929+end
3030+3131+function __fish__get_bun_bun_js_files
3232+ string split ' ' (bun getcompletes j)
3333+end
3434+3535+set -l bun_install_boolean_flags yarn production optional development no-save dry-run force no-cache silent verbose global
3636+set -l bun_install_boolean_flags_descriptions "Write a yarn.lock file (yarn v1)" "Don't install devDependencies" "Add dependency to optionalDependencies" "Add dependency to devDependencies" "Don't install devDependencies" "Don't install anything" "Always request the latest versions from the registry & reinstall all dependencies" "Ignore manifest cache entirely" "Don't output anything" "Excessively verbose logging" "Use global folder"
3737+3838+set -l bun_builtin_cmds_without_run dev create help bun upgrade discord install remove add init pm x
3939+set -l bun_builtin_cmds_accepting_flags create help bun upgrade discord run init link unlink pm x
4040+4141+function __bun_complete_bins_scripts --inherit-variable bun_builtin_cmds_without_run -d "Emit bun completions for bins and scripts"
4242+ # Do nothing if we already have a builtin subcommand,
4343+ # or any subcommand other than "run".
4444+ if __fish_seen_subcommand_from $bun_builtin_cmds_without_run
4545+ or not __fish_use_subcommand && not __fish_seen_subcommand_from run
4646+ return
4747+ end
4848+ # Do we already have a bin or script subcommand?
4949+ set -l bins (__fish__get_bun_bins)
5050+ if __fish_seen_subcommand_from $bins
5151+ return
5252+ end
5353+ # Scripts have descriptions appended with a tab separator.
5454+ # Strip off descriptions for the purposes of subcommand testing.
5555+ set -l scripts (__fish__get_bun_scripts)
5656+ if __fish_seen_subcommand_from $(string split \t -f 1 -- $scripts)
5757+ return
5858+ end
5959+ # Emit scripts.
6060+ for script in $scripts
6161+ echo $script
6262+ end
6363+ # Emit binaries and JS files (but only if we're doing `bun run`).
6464+ if __fish_seen_subcommand_from run
6565+ for bin in $bins
6666+ echo "$bin"\t"package bin"
6767+ end
6868+ for file in (__fish__get_bun_bun_js_files)
6969+ echo "$file"\t"Bun.js"
7070+ end
7171+ end
7272+end
7373+7474+7575+# Clear existing completions
7676+complete -e -c bun
7777+7878+# Dynamically emit scripts and binaries
7979+complete -c bun -f -a "(__bun_complete_bins_scripts)"
8080+8181+# Complete flags if we have no subcommand or a flag-friendly one.
8282+set -l flag_applies "__fish_use_subcommand; or __fish_seen_subcommand_from $bun_builtin_cmds_accepting_flags"
8383+complete -c bun \
8484+ -n $flag_applies --no-files -s 'u' -l 'origin' -r -d 'Server URL. Rewrites import paths'
8585+complete -c bun \
8686+ -n $flag_applies --no-files -s 'p' -l 'port' -r -d 'Port number to start server from'
8787+complete -c bun \
8888+ -n $flag_applies --no-files -s 'd' -l 'define' -r -d 'Substitute K:V while parsing, e.g. --define process.env.NODE_ENV:\"development\"'
8989+complete -c bun \
9090+ -n $flag_applies --no-files -s 'e' -l 'external' -r -d 'Exclude module from transpilation (can use * wildcards). ex: -e react'
9191+complete -c bun \
9292+ -n $flag_applies --no-files -l 'use' -r -d 'Use a framework (ex: next)'
9393+complete -c bun \
9494+ -n $flag_applies --no-files -l 'hot' -r -d 'Enable hot reloading in Bun\'s JavaScript runtime'
9595+9696+# Complete dev and create as first subcommand.
9797+complete -c bun \
9898+ -n "__fish_use_subcommand" -a 'dev' -d 'Start dev server'
9999+complete -c bun \
100100+ -n "__fish_use_subcommand" -a 'create' -f -d 'Create a new project from a template'
101101+102102+# Complete "next" and "react" if we've seen "create".
103103+complete -c bun \
104104+ -n "__fish_seen_subcommand_from create" -a 'next' -d 'new Next.js project'
105105+106106+complete -c bun \
107107+ -n "__fish_seen_subcommand_from create" -a 'react' -d 'new React project'
108108+109109+# Complete "upgrade" as first subcommand.
110110+complete -c bun \
111111+ -n "__fish_use_subcommand" -a 'upgrade' -d 'Upgrade bun to the latest version' -x
112112+# Complete "-h/--help" unconditionally.
113113+complete -c bun \
114114+ -s "h" -l "help" -d 'See all commands and flags' -x
115115+116116+# Complete "-v/--version" if we have no subcommand.
117117+complete -c bun \
118118+ -n "not __fish_use_subcommand" -l "version" -s "v" -d 'Bun\'s version' -x
119119+120120+# Complete additional subcommands.
121121+complete -c bun \
122122+ -n "__fish_use_subcommand" -a 'discord' -d 'Open bun\'s Discord server' -x
123123+124124+125125+complete -c bun \
126126+ -n "__fish_use_subcommand" -a 'bun' -d 'Generate a new bundle'
127127+128128+129129+complete -c bun \
130130+ -n "__fish_seen_subcommand_from bun" -F -d 'Bundle this'
131131+132132+complete -c bun \
133133+ -n "__fish_seen_subcommand_from create; and __fish_seen_subcommand_from react next" -F -d "Create in directory"
134134+135135+136136+complete -c bun \
137137+ -n "__fish_use_subcommand" -a 'init' -F -d 'Start an empty Bun project'
138138+139139+complete -c bun \
140140+ -n "__fish_use_subcommand" -a 'install' -f -d 'Install packages from package.json'
141141+142142+complete -c bun \
143143+ -n "__fish_use_subcommand" -a 'add' -F -d 'Add a package to package.json'
144144+145145+complete -c bun \
146146+ -n "__fish_use_subcommand" -a 'remove' -F -d 'Remove a package from package.json'
147147+148148+149149+for i in (seq (count $bun_install_boolean_flags))
150150+ complete -c bun \
151151+ -n "__fish_seen_subcommand_from install add remove" -l "$bun_install_boolean_flags[$i]" -d "$bun_install_boolean_flags_descriptions[$i]"
152152+end
153153+154154+complete -c bun \
155155+ -n "__fish_seen_subcommand_from install add remove" -l 'cwd' -d 'Change working directory'
156156+157157+complete -c bun \
158158+ -n "__fish_seen_subcommand_from install add remove" -l 'cache-dir' -d 'Choose a cache directory (default: $HOME/.bun/install/cache)'
159159+160160+complete -c bun \
161161+ -n "__fish_seen_subcommand_from add" -d 'Popular' -a '(__fish__get_bun_packages)'
162162+163163+complete -c bun \
164164+ -n "__fish_seen_subcommand_from add" -d 'History' -a '(__history_completions)'
165165+166166+complete -c bun \
167167+ -n "__fish_seen_subcommand_from pm; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts) cache;" -a 'bin ls cache hash hash-print hash-string' -f
168168+169169+complete -c bun \
170170+ -n "__fish_seen_subcommand_from pm; and __fish_seen_subcommand_from cache; and not __fish_seen_subcommand_from (__fish__get_bun_bins) (__fish__get_bun_scripts);" -a 'rm' -f
171171+172172+# Add built-in subcommands with descriptions.
173173+complete -c bun -n "__fish_use_subcommand" -a "create" -f -d "Create a new project from a template"
174174+complete -c bun -n "__fish_use_subcommand" -a "build bun" --require-parameter -F -d "Transpile and bundle one or more files"
175175+complete -c bun -n "__fish_use_subcommand" -a "upgrade" -d "Upgrade Bun"
176176+complete -c bun -n "__fish_use_subcommand" -a "run" -d "Run a script or package binary"
177177+complete -c bun -n "__fish_use_subcommand" -a "install" -d "Install dependencies from package.json" -f
178178+complete -c bun -n "__fish_use_subcommand" -a "remove" -d "Remove a dependency from package.json" -f
179179+complete -c bun -n "__fish_use_subcommand" -a "add" -d "Add a dependency to package.json" -f
180180+complete -c bun -n "__fish_use_subcommand" -a "init" -d "Initialize a Bun project in this directory" -f
181181+complete -c bun -n "__fish_use_subcommand" -a "link" -d "Register or link a local npm package" -f
182182+complete -c bun -n "__fish_use_subcommand" -a "link" -d "Unregister a local npm package" -f
183183+complete -c bun -n "__fish_use_subcommand" -a "pm" -d "Additional package management utilities" -f
184184+complete -c bun -n "__fish_use_subcommand" -a "x" -d "Execute a package binary, installing if needed" -f
+8
fish/completions/fzf_configure_bindings.fish
···11+complete fzf_configure_bindings --no-files
22+complete fzf_configure_bindings --long help --short h --description "Print help" --condition "not __fish_seen_argument --help -h"
33+complete fzf_configure_bindings --long directory --description "Change the key binding for Search Directory" --condition "not __fish_seen_argument --directory"
44+complete fzf_configure_bindings --long git_log --description "Change the key binding for Search Git Log" --condition "not __fish_seen_argument --git_log"
55+complete fzf_configure_bindings --long git_status --description "Change the key binding for Search Git Status" --condition "not __fish_seen_argument --git_status"
66+complete fzf_configure_bindings --long history --description "Change the key binding for Search History" --condition "not __fish_seen_argument --history"
77+complete fzf_configure_bindings --long processes --description "Change the key binding for Search Processes" --condition "not __fish_seen_argument --processes"
88+complete fzf_configure_bindings --long variables --description "Change the key binding for Search Variables" --condition "not __fish_seen_argument --variables"
+28
fish/conf.d/fzf.fish
···11+# fzf.fish is only meant to be used in interactive mode. If not in interactive mode and not in CI, skip the config to speed up shell startup
22+if not status is-interactive && test "$CI" != true
33+ exit
44+end
55+66+# Because of scoping rules, to capture the shell variables exactly as they are, we must read
77+# them before even executing _fzf_search_variables. We use psub to store the
88+# variables' info in temporary files and pass in the filenames as arguments.
99+# This variable is global so that it can be referenced by fzf_configure_bindings and in tests
1010+set --global _fzf_search_vars_command '_fzf_search_variables (set --show | psub) (set --names | psub)'
1111+1212+1313+# Install the default bindings, which are mnemonic and minimally conflict with fish's preset bindings
1414+fzf_configure_bindings
1515+1616+# Doesn't erase autoloaded _fzf_* functions because they are not easily accessible once key bindings are erased
1717+function _fzf_uninstall --on-event fzf_uninstall
1818+ _fzf_uninstall_bindings
1919+2020+ set --erase _fzf_search_vars_command
2121+ functions --erase _fzf_uninstall _fzf_migration_message _fzf_uninstall_bindings fzf_configure_bindings
2222+ complete --erase fzf_configure_bindings
2323+2424+ set_color cyan
2525+ echo "fzf.fish uninstalled."
2626+ echo "You may need to manually remove fzf_configure_bindings from your config.fish if you were using custom key bindings."
2727+ set_color normal
2828+end
···11/home/linuxbrew/.linuxbrew/bin/brew shellenv | source
2233+fish_add_path /home/vpb/.local/bin
44+35if status is-interactive
46 set fish_greeting
77+ set EDITOR nvim
88+59 # Commands to run in interactive sessions can go here
610 starship init fish | source
711 direnv hook fish | source
1212+ nvm use latest
813end
9141010-fish_add_path /home/vpb/.local/bin
11151212-fish_add_path /home/vpb/.rvm/bin
1313-rvm default
1616+# Created by `pipx` on 2024-04-12 12:49:16
1717+set PATH $PATH /home/vitorpy/.local/bin
14181515-fish_add_path /home/vpb/.local/share/solana/install/active_release/bin
1616-fish_add_path /home/vpb/.foundry/bin
1919+# bun
2020+set --export BUN_INSTALL "$HOME/.bun"
2121+set --export PATH $BUN_INSTALL/bin $PATH
17221818-fish_add_path /home/vpb/.cargo/bin
2323+set ANTHROPIC_API_KEY "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"
19242020-nvm use latest
2121-pyenv init - | source
2222-2323-fish_add_path -a /home/vpb/.config/.foundry/bin
2525+# The next line updates PATH for the Google Cloud SDK.
2626+if [ -f '/home/vitorpy/google-cloud-sdk/path.fish.inc' ]; . '/home/vitorpy/google-cloud-sdk/path.fish.inc'; end
+21
fish/config.fish.backup
···11+/home/linuxbrew/.linuxbrew/bin/brew shellenv | source
22+33+fish_add_path /home/vpb/.local/bin
44+55+if status is-interactive
66+ set fish_greeting
77+ set EDITOR nvim
88+99+ # Commands to run in interactive sessions can go here
1010+ starship init fish | source
1111+ direnv hook fish | source
1212+ nvm use latest
1313+end
1414+1515+1616+# Created by `pipx` on 2024-04-12 12:49:16
1717+set PATH $PATH /home/vitorpy/.local/bin
1818+1919+# bun
2020+set --export BUN_INSTALL "$HOME/.bun"
2121+set --export PATH $BUN_INSTALL/bin $PATH
···11+function _fzf_configure_bindings_help --description "Prints the help message for fzf_configure_bindings."
22+ echo "\
33+USAGE:
44+ fzf_configure_bindings [--COMMAND=[KEY_SEQUENCE]...]
55+66+DESCRIPTION
77+ fzf_configure_bindings installs key bindings for fzf.fish's commands and erases any bindings it
88+ previously installed. It installs bindings for both default and insert modes. fzf.fish executes
99+ it without options on fish startup to install the out-of-the-box key bindings.
1010+1111+ By default, commands are bound to a mnemonic key sequence, shown below. Each command's binding
1212+ can be configured using a namesake corresponding option:
1313+ COMMAND | DEFAULT KEY SEQUENCE | CORRESPONDING OPTION
1414+ Search Directory | Ctrl+Alt+F (F for file) | --directory
1515+ Search Git Log | Ctrl+Alt+L (L for log) | --git_log
1616+ Search Git Status | Ctrl+Alt+S (S for status) | --git_status
1717+ Search History | Ctrl+R (R for reverse) | --history
1818+ Search Processes | Ctrl+Alt+P (P for process) | --processes
1919+ Search Variables | Ctrl+V (V for variable) | --variables
2020+ Override a command's binding by specifying its corresponding option with the desired key
2121+ sequence. Disable a command's binding by specifying its corresponding option with no value.
2222+2323+ Because fzf_configure_bindings erases bindings it previously installed, it can be cleanly
2424+ executed multiple times. Once the desired fzf_configure_bindings command has been found, add it
2525+ to your config.fish in order to persist the customized bindings.
2626+2727+ In terms of validation, fzf_configure_bindings fails if passed unknown options. It expects an
2828+ equals sign between an option's name and value. However, it does not validate key sequences.
2929+3030+ Pass -h or --help to print this help message and exit.
3131+3232+EXAMPLES
3333+ Default bindings but bind Search Directory to Ctrl+F and Search Variables to Ctrl+Alt+V
3434+ \$ fzf_configure_bindings --directory=\cf --variables=\e\cv
3535+ Default bindings but disable Search History
3636+ \$ fzf_configure_bindings --history=
3737+ An agglomeration of different options
3838+ \$ fzf_configure_bindings --git_status=\cg --history=\ch --variables= --processes=
3939+4040+SEE Also
4141+ To learn more about fish key bindings, see bind(1) and fish_key_reader(1).
4242+"
4343+end
+15
fish/functions/_fzf_extract_var_info.fish
···11+# helper function for _fzf_search_variables
22+function _fzf_extract_var_info --argument-names variable_name set_show_output --description "Extract and reformat lines pertaining to \$variable_name from \$set_show_output."
33+ # Extract only the lines about the variable, all of which begin with either
44+ # $variable_name: ...or... $variable_name[
55+ string match --regex "^\\\$$variable_name(?::|\[).*" <$set_show_output |
66+77+ # Strip the variable name prefix, including ": " for scope info lines
88+ string replace --regex "^\\\$$variable_name(?:: )?" '' |
99+1010+ # Distill the lines of values, replacing...
1111+ # [1]: |value|
1212+ # ...with...
1313+ # [1] value
1414+ string replace --regex ": \|(.*)\|" ' $1'
1515+end
+49
fish/functions/_fzf_preview_changed_file.fish
···11+# helper for _fzf_search_git_status
22+# arg should be a line from git status --short, e.g.
33+# MM functions/_fzf_preview_changed_file.fish
44+# D README.md
55+# R LICENSE -> "New License"
66+function _fzf_preview_changed_file --argument-names path_status --description "Show the git diff of the given file."
77+ # remove quotes because they'll be interpreted literally by git diff
88+ # no need to requote when referencing $path because fish does not perform word splitting
99+ # https://fishshell.com/docs/current/fish_for_bash_users.html
1010+ set -f path (string unescape (string sub --start 4 $path_status))
1111+ # first letter of short format shows index, second letter shows working tree
1212+ # https://git-scm.com/docs/git-status/2.35.0#_short_format
1313+ set -f index_status (string sub --length 1 $path_status)
1414+ set -f working_tree_status (string sub --start 2 --length 1 $path_status)
1515+1616+ set -f diff_opts --color=always
1717+1818+ if test $index_status = '?'
1919+ _fzf_report_diff_type Untracked
2020+ _fzf_preview_file $path
2121+ else if contains {$index_status}$working_tree_status DD AU UD UA DU AA UU
2222+ # Unmerged statuses taken directly from git status help's short format table
2323+ # Unmerged statuses are mutually exclusive with other statuses, so if we see
2424+ # these, then safe to assume the path is unmerged
2525+ _fzf_report_diff_type Unmerged
2626+ git diff $diff_opts -- $path
2727+ else
2828+ if test $index_status != ' '
2929+ _fzf_report_diff_type Staged
3030+3131+ # renames are only detected in the index, never working tree, so only need to test for it here
3232+ # https://stackoverflow.com/questions/73954214
3333+ if test $index_status = R
3434+ # diff the post-rename path with the original path, otherwise the diff will show the entire file as being added
3535+ set -f orig_and_new_path (string split --max 1 -- ' -> ' $path)
3636+ git diff --staged $diff_opts -- $orig_and_new_path[1] $orig_and_new_path[2]
3737+ # path currently has the form of "original -> current", so we need to correct it before it's used below
3838+ set path $orig_and_new_path[2]
3939+ else
4040+ git diff --staged $diff_opts -- $path
4141+ end
4242+ end
4343+4444+ if test $working_tree_status != ' '
4545+ _fzf_report_diff_type Unstaged
4646+ git diff $diff_opts -- $path
4747+ end
4848+ end
4949+end
+43
fish/functions/_fzf_preview_file.fish
···11+# helper function for _fzf_search_directory and _fzf_search_git_status
22+function _fzf_preview_file --description "Print a preview for the given file based on its file type."
33+ # because there's no way to guarantee that _fzf_search_directory passes the path to _fzf_preview_file
44+ # as one argument, we collect all the arguments into one single variable and treat that as the path
55+ set -f file_path $argv
66+77+ if test -L "$file_path" # symlink
88+ # notify user and recurse on the target of the symlink, which can be any of these file types
99+ set -l target_path (realpath "$file_path")
1010+1111+ set_color yellow
1212+ echo "'$file_path' is a symlink to '$target_path'."
1313+ set_color normal
1414+1515+ _fzf_preview_file "$target_path"
1616+ else if test -f "$file_path" # regular file
1717+ if set --query fzf_preview_file_cmd
1818+ # need to escape quotes to make sure eval receives file_path as a single arg
1919+ eval "$fzf_preview_file_cmd '$file_path'"
2020+ else
2121+ bat --style=numbers --color=always "$file_path"
2222+ end
2323+ else if test -d "$file_path" # directory
2424+ if set --query fzf_preview_dir_cmd
2525+ # see above
2626+ eval "$fzf_preview_dir_cmd '$file_path'"
2727+ else
2828+ # -A list hidden files as well, except for . and ..
2929+ # -F helps classify files by appending symbols after the file name
3030+ command ls -A -F "$file_path"
3131+ end
3232+ else if test -c "$file_path"
3333+ _fzf_report_file_type "$file_path" "character device file"
3434+ else if test -b "$file_path"
3535+ _fzf_report_file_type "$file_path" "block device file"
3636+ else if test -S "$file_path"
3737+ _fzf_report_file_type "$file_path" socket
3838+ else if test -p "$file_path"
3939+ _fzf_report_file_type "$file_path" "named pipe"
4040+ else
4141+ echo "$file_path doesn't exist." >&2
4242+ end
4343+end
+18
fish/functions/_fzf_report_diff_type.fish
···11+# helper for _fzf_preview_changed_file
22+# prints out something like
33+# ╭────────╮
44+# │ Staged │
55+# ╰────────╯
66+function _fzf_report_diff_type --argument-names diff_type --description "Print a distinct colored header meant to preface a git patch."
77+ # number of "-" to draw is the length of the string to box + 2 for padding
88+ set -f repeat_count (math 2 + (string length $diff_type))
99+ set -f line (string repeat --count $repeat_count ─)
1010+ set -f top_border ╭$line╮
1111+ set -f btm_border ╰$line╯
1212+1313+ set_color yellow
1414+ echo $top_border
1515+ echo "│ $diff_type │"
1616+ echo $btm_border
1717+ set_color normal
1818+end
+6
fish/functions/_fzf_report_file_type.fish
···11+# helper function for _fzf_preview_file
22+function _fzf_report_file_type --argument-names file_path file_type --description "Explain the file type for a file."
33+ set_color red
44+ echo "Cannot preview '$file_path': it is a $file_type."
55+ set_color normal
66+end
+33
fish/functions/_fzf_search_directory.fish
···11+function _fzf_search_directory --description "Search the current directory. Replace the current token with the selected file paths."
22+ # Directly use fd binary to avoid output buffering delay caused by a fd alias, if any.
33+ # Debian-based distros install fd as fdfind and the fd package is something else, so
44+ # check for fdfind first. Fall back to "fd" for a clear error message.
55+ set -f fd_cmd (command -v fdfind || command -v fd || echo "fd")
66+ set -f --append fd_cmd --color=always $fzf_fd_opts
77+88+ set -f fzf_arguments --multi --ansi $fzf_directory_opts
99+ set -f token (commandline --current-token)
1010+ # expand any variables or leading tilde (~) in the token
1111+ set -f expanded_token (eval echo -- $token)
1212+ # unescape token because it's already quoted so backslashes will mess up the path
1313+ set -f unescaped_exp_token (string unescape -- $expanded_token)
1414+1515+ # If the current token is a directory and has a trailing slash,
1616+ # then use it as fd's base directory.
1717+ if string match --quiet -- "*/" $unescaped_exp_token && test -d "$unescaped_exp_token"
1818+ set --append fd_cmd --base-directory=$unescaped_exp_token
1919+ # use the directory name as fzf's prompt to indicate the search is limited to that directory
2020+ set --prepend fzf_arguments --prompt="Directory $unescaped_exp_token> " --preview="_fzf_preview_file $expanded_token{}"
2121+ set -f file_paths_selected $unescaped_exp_token($fd_cmd 2>/dev/null | _fzf_wrapper $fzf_arguments)
2222+ else
2323+ set --prepend fzf_arguments --prompt="Directory> " --query="$unescaped_exp_token" --preview='_fzf_preview_file {}'
2424+ set -f file_paths_selected ($fd_cmd 2>/dev/null | _fzf_wrapper $fzf_arguments)
2525+ end
2626+2727+2828+ if test $status -eq 0
2929+ commandline --current-token --replace -- (string escape -- $file_paths_selected | string join ' ')
3030+ end
3131+3232+ commandline --function repaint
3333+end
+36
fish/functions/_fzf_search_git_log.fish
···11+function _fzf_search_git_log --description "Search the output of git log and preview commits. Replace the current token with the selected commit hash."
22+ if not git rev-parse --git-dir >/dev/null 2>&1
33+ echo '_fzf_search_git_log: Not in a git repository.' >&2
44+ else
55+ if not set --query fzf_git_log_format
66+ # %h gives you the abbreviated commit hash, which is useful for saving screen space, but we will have to expand it later below
77+ set -f fzf_git_log_format '%C(bold blue)%h%C(reset) - %C(cyan)%ad%C(reset) %C(yellow)%d%C(reset) %C(normal)%s%C(reset) %C(dim normal)[%an]%C(reset)'
88+ end
99+1010+ set -f preview_cmd 'git show --color=always --stat --patch {1}'
1111+ if set --query fzf_diff_highlighter
1212+ set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
1313+ end
1414+1515+ set -f selected_log_lines (
1616+ git log --no-show-signature --color=always --format=format:$fzf_git_log_format --date=short | \
1717+ _fzf_wrapper --ansi \
1818+ --multi \
1919+ --scheme=history \
2020+ --prompt="Git Log> " \
2121+ --preview=$preview_cmd \
2222+ --query=(commandline --current-token) \
2323+ $fzf_git_log_opts
2424+ )
2525+ if test $status -eq 0
2626+ for line in $selected_log_lines
2727+ set -f abbreviated_commit_hash (string split --field 1 " " $line)
2828+ set -f full_commit_hash (git rev-parse $abbreviated_commit_hash)
2929+ set -f --append commit_hashes $full_commit_hash
3030+ end
3131+ commandline --current-token --replace (string join ' ' $commit_hashes)
3232+ end
3333+ end
3434+3535+ commandline --function repaint
3636+end
+41
fish/functions/_fzf_search_git_status.fish
···11+function _fzf_search_git_status --description "Search the output of git status. Replace the current token with the selected file paths."
22+ if not git rev-parse --git-dir >/dev/null 2>&1
33+ echo '_fzf_search_git_status: Not in a git repository.' >&2
44+ else
55+ set -f preview_cmd '_fzf_preview_changed_file {}'
66+ if set --query fzf_diff_highlighter
77+ set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
88+ end
99+1010+ set -f selected_paths (
1111+ # Pass configuration color.status=always to force status to use colors even though output is sent to a pipe
1212+ git -c color.status=always status --short |
1313+ _fzf_wrapper --ansi \
1414+ --multi \
1515+ --prompt="Git Status> " \
1616+ --query=(commandline --current-token) \
1717+ --preview=$preview_cmd \
1818+ --nth="2.." \
1919+ $fzf_git_status_opts
2020+ )
2121+ if test $status -eq 0
2222+ # git status --short automatically escapes the paths of most files for us so not going to bother trying to handle
2323+ # the few edges cases of weird file names that should be extremely rare (e.g. "this;needs;escaping")
2424+ set -f cleaned_paths
2525+2626+ for path in $selected_paths
2727+ if test (string sub --length 1 $path) = R
2828+ # path has been renamed and looks like "R LICENSE -> LICENSE.md"
2929+ # extract the path to use from after the arrow
3030+ set --append cleaned_paths (string split -- "-> " $path)[-1]
3131+ else
3232+ set --append cleaned_paths (string sub --start=4 $path)
3333+ end
3434+ end
3535+3636+ commandline --current-token --replace -- (string join ' ' $cleaned_paths)
3737+ end
3838+ end
3939+4040+ commandline --function repaint
4141+end
+39
fish/functions/_fzf_search_history.fish
···11+function _fzf_search_history --description "Search command history. Replace the command line with the selected command."
22+ # history merge incorporates history changes from other fish sessions
33+ # it errors out if called in private mode
44+ if test -z "$fish_private_mode"
55+ builtin history merge
66+ end
77+88+ if not set --query fzf_history_time_format
99+ # Reference https://devhints.io/strftime to understand strftime format symbols
1010+ set -f fzf_history_time_format "%m-%d %H:%M:%S"
1111+ end
1212+1313+ # Delinate time from command in history entries using the vertical box drawing char (U+2502).
1414+ # Then, to get raw command from history entries, delete everything up to it. The ? on regex is
1515+ # necessary to make regex non-greedy so it won't match into commands containing the char.
1616+ set -f time_prefix_regex '^.*? │ '
1717+ # Delinate commands throughout pipeline using null rather than newlines because commands can be multi-line
1818+ set -f commands_selected (
1919+ builtin history --null --show-time="$fzf_history_time_format │ " |
2020+ _fzf_wrapper --read0 \
2121+ --print0 \
2222+ --multi \
2323+ --scheme=history \
2424+ --prompt="History> " \
2525+ --query=(commandline) \
2626+ --preview="string replace --regex '$time_prefix_regex' '' -- {} | fish_indent --ansi" \
2727+ --preview-window="bottom:3:wrap" \
2828+ $fzf_history_opts |
2929+ string split0 |
3030+ # remove timestamps from commands selected
3131+ string replace --regex $time_prefix_regex ''
3232+ )
3333+3434+ if test $status -eq 0
3535+ commandline --replace -- $commands_selected
3636+ end
3737+3838+ commandline --function repaint
3939+end
+32
fish/functions/_fzf_search_processes.fish
···11+function _fzf_search_processes --description "Search all running processes. Replace the current token with the pid of the selected process."
22+ # Directly use ps command because it is often aliased to a different command entirely
33+ # or with options that dirty the search results and preview output
44+ set -f ps_cmd (command -v ps || echo "ps")
55+ # use all caps to be consistent with ps default format
66+ # snake_case because ps doesn't seem to allow spaces in the field names
77+ set -f ps_preview_fmt (string join ',' 'pid' 'ppid=PARENT' 'user' '%cpu' 'rss=RSS_IN_KB' 'start=START_TIME' 'command')
88+ set -f processes_selected (
99+ $ps_cmd -A -opid,command | \
1010+ _fzf_wrapper --multi \
1111+ --prompt="Processes> " \
1212+ --query (commandline --current-token) \
1313+ --ansi \
1414+ # first line outputted by ps is a header, so we need to mark it as so
1515+ --header-lines=1 \
1616+ # ps uses exit code 1 if the process was not found, in which case show an message explaining so
1717+ --preview="$ps_cmd -o '$ps_preview_fmt' -p {1} || echo 'Cannot preview {1} because it exited.'" \
1818+ --preview-window="bottom:4:wrap" \
1919+ $fzf_processes_opts
2020+ )
2121+2222+ if test $status -eq 0
2323+ for process in $processes_selected
2424+ set -f --append pids_selected (string split --no-empty --field=1 -- " " $process)
2525+ end
2626+2727+ # string join to replace the newlines outputted by string split with spaces
2828+ commandline --current-token --replace -- (string join ' ' $pids_selected)
2929+ end
3030+3131+ commandline --function repaint
3232+end
+47
fish/functions/_fzf_search_variables.fish
···11+# This function expects the following two arguments:
22+# argument 1 = output of (set --show | psub), i.e. a file with the scope info and values of all variables
33+# argument 2 = output of (set --names | psub), i.e. a file with all variable names
44+function _fzf_search_variables --argument-names set_show_output set_names_output --description "Search and preview shell variables. Replace the current token with the selected variable."
55+ if test -z "$set_names_output"
66+ printf '%s\n' '_fzf_search_variables requires 2 arguments.' >&2
77+88+ commandline --function repaint
99+ return 22 # 22 means invalid argument in POSIX
1010+ end
1111+1212+ # Exclude the history variable from being piped into fzf because
1313+ # 1. it's not included in $set_names_output
1414+ # 2. it tends to be a very large value => increases computation time
1515+ # 3._fzf_search_history is a much better way to examine history anyway
1616+ set -f all_variable_names (string match --invert history <$set_names_output)
1717+1818+ set -f current_token (commandline --current-token)
1919+ # Use the current token to pre-populate fzf's query. If the current token begins
2020+ # with a $, remove it from the query so that it will better match the variable names
2121+ set -f cleaned_curr_token (string replace -- '$' '' $current_token)
2222+2323+ set -f variable_names_selected (
2424+ printf '%s\n' $all_variable_names |
2525+ _fzf_wrapper --preview "_fzf_extract_var_info {} $set_show_output" \
2626+ --prompt="Variables> " \
2727+ --preview-window="wrap" \
2828+ --multi \
2929+ --query=$cleaned_curr_token \
3030+ $fzf_variables_opts
3131+ )
3232+3333+ if test $status -eq 0
3434+ # If the current token begins with a $, do not overwrite the $ when
3535+ # replacing the current token with the selected variable.
3636+ # Uses brace expansion to prepend $ to each variable name.
3737+ commandline --current-token --replace (
3838+ if string match --quiet -- '$*' $current_token
3939+ string join " " \${$variable_names_selected}
4040+ else
4141+ string join " " $variable_names_selected
4242+ end
4343+ )
4444+ end
4545+4646+ commandline --function repaint
4747+end
+21
fish/functions/_fzf_wrapper.fish
···11+function _fzf_wrapper --description "Prepares some environment variables before executing fzf."
22+ # Make sure fzf uses fish to execute preview commands, some of which
33+ # are autoloaded fish functions so don't exist in other shells.
44+ # Use --function so that it doesn't clobber SHELL outside this function.
55+ set -f --export SHELL (command --search fish)
66+77+ # If neither FZF_DEFAULT_OPTS nor FZF_DEFAULT_OPTS_FILE are set, then set some sane defaults.
88+ # See https://github.com/junegunn/fzf#environment-variables
99+ set --query FZF_DEFAULT_OPTS FZF_DEFAULT_OPTS_FILE
1010+ if test $status -eq 2
1111+ # cycle allows jumping between the first and last results, making scrolling faster
1212+ # layout=reverse lists results top to bottom, mimicking the familiar layouts of git log, history, and env
1313+ # border shows where the fzf window begins and ends
1414+ # height=90% leaves space to see the current command and some scrollback, maintaining context of work
1515+ # preview-window=wrap wraps long lines in the preview window, making reading easier
1616+ # marker=* makes the multi-select marker more distinguishable from the pointer (since both default to >)
1717+ set --export FZF_DEFAULT_OPTS '--cycle --layout=reverse --border --height=90% --preview-window=wrap --marker="*"'
1818+ end
1919+2020+ fzf $argv
2121+end
-4
fish/functions/bat.fish
···11-function bat --wraps=batcat --description 'alias bat=batcat'
22- batcat $argv
33-44-end
···11+# Always installs bindings for insert and default mode for simplicity and b/c it has almost no side-effect
22+# https://gitter.im/fish-shell/fish-shell?at=60a55915ee77a74d685fa6b1
33+function fzf_configure_bindings --description "Installs the default key bindings for fzf.fish with user overrides passed as options."
44+ # no need to install bindings if not in interactive mode or running tests
55+ status is-interactive || test "$CI" = true; or return
66+77+ set -f options_spec h/help 'directory=?' 'git_log=?' 'git_status=?' 'history=?' 'processes=?' 'variables=?'
88+ argparse --max-args=0 --ignore-unknown $options_spec -- $argv 2>/dev/null
99+ if test $status -ne 0
1010+ echo "Invalid option or a positional argument was provided." >&2
1111+ _fzf_configure_bindings_help
1212+ return 22
1313+ else if set --query _flag_help
1414+ _fzf_configure_bindings_help
1515+ return
1616+ else
1717+ # Initialize with default key sequences and then override or disable them based on flags
1818+ # index 1 = directory, 2 = git_log, 3 = git_status, 4 = history, 5 = processes, 6 = variables
1919+ set -f key_sequences \e\cf \e\cl \e\cs \cr \e\cp \cv # \c = control, \e = escape
2020+ set --query _flag_directory && set key_sequences[1] "$_flag_directory"
2121+ set --query _flag_git_log && set key_sequences[2] "$_flag_git_log"
2222+ set --query _flag_git_status && set key_sequences[3] "$_flag_git_status"
2323+ set --query _flag_history && set key_sequences[4] "$_flag_history"
2424+ set --query _flag_processes && set key_sequences[5] "$_flag_processes"
2525+ set --query _flag_variables && set key_sequences[6] "$_flag_variables"
2626+2727+ # If fzf bindings already exists, uninstall it first for a clean slate
2828+ if functions --query _fzf_uninstall_bindings
2929+ _fzf_uninstall_bindings
3030+ end
3131+3232+ for mode in default insert
3333+ test -n $key_sequences[1] && bind --mode $mode $key_sequences[1] _fzf_search_directory
3434+ test -n $key_sequences[2] && bind --mode $mode $key_sequences[2] _fzf_search_git_log
3535+ test -n $key_sequences[3] && bind --mode $mode $key_sequences[3] _fzf_search_git_status
3636+ test -n $key_sequences[4] && bind --mode $mode $key_sequences[4] _fzf_search_history
3737+ test -n $key_sequences[5] && bind --mode $mode $key_sequences[5] _fzf_search_processes
3838+ test -n $key_sequences[6] && bind --mode $mode $key_sequences[6] "$_fzf_search_vars_command"
3939+ end
4040+4141+ function _fzf_uninstall_bindings --inherit-variable key_sequences
4242+ bind --erase -- $key_sequences
4343+ bind --erase --mode insert -- $key_sequences
4444+ end
4545+ end
4646+end