deleted: .config/apps-list.md modified: .config/btop/btop.conf deleted: .config/config.kdl new file: .config/fish/completions/fisher.fish new file: .config/fish/completions/fzf_configure_bindings.fish new file: .config/fish/conf.d/fzf.fish new file: .config/fish/fish_plugins modified: .config/fish/fish_variables new file: .config/fish/functions/_fzf_configure_bindings_help.fish new file: .config/fish/functions/_fzf_extract_var_info.fish new file: .config/fish/functions/_fzf_preview_changed_file.fish new file: .config/fish/functions/_fzf_preview_file.fish new file: .config/fish/functions/_fzf_report_diff_type.fish new file: .config/fish/functions/_fzf_report_file_type.fish new file: .config/fish/functions/_fzf_search_directory.fish new file: .config/fish/functions/_fzf_search_git_log.fish new file: .config/fish/functions/_fzf_search_git_status.fish new file: .config/fish/functions/_fzf_search_history.fish new file: .config/fish/functions/_fzf_search_processes.fish new file: .config/fish/functions/_fzf_search_variables.fish new file: .config/fish/functions/_fzf_wrapper.fish new file: .config/fish/functions/fisher.fish new file: .config/fish/functions/fzf_configure_bindings.fish new file: .config/fish/functions/y.fish new file: .config/fish/functions/yz.fish new file: ".config/fish/functions/\320\275\321\217.fish" modified: .config/kitty/kitty.conf modified: .config/niri/config.kdl modified: .config/nvim/lazy-lock.json new file: .config/nvim/lua/plugins/luasnip.lua new file: .config/nvim/lua/plugins/markview.lua new file: .config/nvim/lua/plugins/marp-nvim.lua new file: .config/nvim/lua/plugins/nvim-snippy.lua new file: .config/nvim/lua/plugins/render-markdown.lua deleted: .config/nwg-look/config deleted: .config/zathura/zathurarc modified: apps-list.md new file: background renamed: .config/mimeapps.list -> mimeapps.list renamed: .config/pavucontrol.ini -> pavucontrol.ini deleted: sing-box-03.json renamed: .config/user-dirs.dirs -> user-dirs.dirs renamed: .config/user-dirs.locale -> user-dirs.locale
47 lines
2.1 KiB
Fish
47 lines
2.1 KiB
Fish
# This function expects the following two arguments:
|
|
# argument 1 = output of (set --show | psub), i.e. a file with the scope info and values of all variables
|
|
# argument 2 = output of (set --names | psub), i.e. a file with all variable names
|
|
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."
|
|
if test -z "$set_names_output"
|
|
printf '%s\n' '_fzf_search_variables requires 2 arguments.' >&2
|
|
|
|
commandline --function repaint
|
|
return 22 # 22 means invalid argument in POSIX
|
|
end
|
|
|
|
# Exclude the history variable from being piped into fzf because
|
|
# 1. it's not included in $set_names_output
|
|
# 2. it tends to be a very large value => increases computation time
|
|
# 3._fzf_search_history is a much better way to examine history anyway
|
|
set -f all_variable_names (string match --invert history <$set_names_output)
|
|
|
|
set -f current_token (commandline --current-token)
|
|
# Use the current token to pre-populate fzf's query. If the current token begins
|
|
# with a $, remove it from the query so that it will better match the variable names
|
|
set -f cleaned_curr_token (string replace -- '$' '' $current_token)
|
|
|
|
set -f variable_names_selected (
|
|
printf '%s\n' $all_variable_names |
|
|
_fzf_wrapper --preview "_fzf_extract_var_info {} $set_show_output" \
|
|
--prompt="Variables> " \
|
|
--preview-window="wrap" \
|
|
--multi \
|
|
--query=$cleaned_curr_token \
|
|
$fzf_variables_opts
|
|
)
|
|
|
|
if test $status -eq 0
|
|
# If the current token begins with a $, do not overwrite the $ when
|
|
# replacing the current token with the selected variable.
|
|
# Uses brace expansion to prepend $ to each variable name.
|
|
commandline --current-token --replace (
|
|
if string match --quiet -- '$*' $current_token
|
|
string join " " \${$variable_names_selected}
|
|
else
|
|
string join " " $variable_names_selected
|
|
end
|
|
)
|
|
end
|
|
|
|
commandline --function repaint
|
|
end
|