diff options
Diffstat (limited to '.config/fish/conf.d')
-rw-r--r-- | .config/fish/conf.d/_tide_init.fish | 41 | ||||
-rw-r--r-- | .config/fish/conf.d/abbr_tips.fish | 155 | ||||
-rw-r--r-- | .config/fish/conf.d/fzf.fish | 28 | ||||
-rw-r--r-- | .config/fish/conf.d/halostatue_fish_docker.fish | 31 |
4 files changed, 255 insertions, 0 deletions
diff --git a/.config/fish/conf.d/_tide_init.fish b/.config/fish/conf.d/_tide_init.fish new file mode 100644 index 00000000..939f17c9 --- /dev/null +++ b/.config/fish/conf.d/_tide_init.fish @@ -0,0 +1,41 @@ +function _tide_init_install --on-event _tide_init_install + set -U VIRTUAL_ENV_DISABLE_PROMPT true + + source (functions --details _tide_sub_configure) + _load_config lean + _tide_finish + + if status is-interactive + tide bug-report --check || sleep 4 + + if contains ilancosman/tide (string lower $_fisher_plugins) + set_color bryellow + echo "ilancosman/tide is a development branch. Please install from a release tag:" + echo -ns "fisher install ilancosman/tide@v5" | fish_indent --ansi + sleep 3 + end + + switch (read --prompt-str="Configure tide prompt? [Y/n] " | string lower) + case y ye yes '' + tide configure + case '*' + echo -s \n 'Run ' (echo -ns "tide configure" | fish_indent --ansi) ' to customize your prompt.' + end + end +end + +function _tide_init_update --on-event _tide_init_update + # Warn users who install from main branch + if contains ilancosman/tide (string lower $_fisher_plugins) + set_color bryellow + echo "ilancosman/tide is a development branch. Please install from a release tag:" + echo -ns "fisher install ilancosman/tide@v5" | fish_indent --ansi + sleep 3 + end +end + +function _tide_init_uninstall --on-event _tide_init_uninstall + set -e VIRTUAL_ENV_DISABLE_PROMPT + set -e (set -U --names | string match --entire -r '^_?tide') + functions --erase (functions --all | string match --entire -r '^_?tide') +end diff --git a/.config/fish/conf.d/abbr_tips.fish b/.config/fish/conf.d/abbr_tips.fish new file mode 100644 index 00000000..848ee6da --- /dev/null +++ b/.config/fish/conf.d/abbr_tips.fish @@ -0,0 +1,155 @@ +for mode in default insert + bind --mode $mode " " '__abbr_tips_bind_space' + bind --mode $mode \n '__abbr_tips_bind_newline' + bind --mode $mode \r '__abbr_tips_bind_newline' +end + +set -g __abbr_tips_used 0 + +# Trim simple/double quotes from args +function trim_value + echo "$argv" | string trim --left --right --chars '"\'' | string join ' ' +end + +function __abbr_tips_install --on-event abbr_tips_install + # Regexes used to find abbreviation inside command + # Only the first matching group will be tested as an abbr + set -Ux ABBR_TIPS_REGEXES + set -a ABBR_TIPS_REGEXES '(^(\w+\s+)+(-{1,2})\w+)(\s\S+)' + set -a ABBR_TIPS_REGEXES '(^(\s?(\w-?)+){3}).*' + set -a ABBR_TIPS_REGEXES '(^(\s?(\w-?)+){2}).*' + set -a ABBR_TIPS_REGEXES '(^(\s?(\w-?)+){1}).*' + + set -Ux ABBR_TIPS_PROMPT "\n💡 \e[1m{{ .abbr }}\e[0m => {{ .cmd }}" + set -gx ABBR_TIPS_AUTO_UPDATE 'background' + + # Locking mechanism + # Prevent this file to spawn more than one subshell + if test "$USER" != 'root' + fish -c '__abbr_tips_init' & + end +end + +function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the current command" + set -l command (string split ' ' -- "$argv") + set -l cmd (string replace -r -a '\\s+' ' ' -- "$argv" ) + + # Update abbreviations lists when adding/removing abbreviations + if test "$command[1]" = "abbr" + # Parse args as abbr options + argparse --name 'abbr' --ignore-unknown 'a/add' 'e/erase' 'g/global' 'U/universal' -- $command + + if set -q _flag_a + and not contains -- "$argv[2]" $__ABBR_TIPS_KEYS + set -a __ABBR_TIPS_KEYS "$argv[2]" + set -a __ABBR_TIPS_VALUES (trim_value "$argv[3..-1]") + else if set -q _flag_e + and set -l abb (contains -i -- "$argv[2]" $__ABBR_TIPS_KEYS) + set -e __ABBR_TIPS_KEYS[$abb] + set -e __ABBR_TIPS_VALUES[$abb] + end + else if test "$command[1]" = "alias" + # Update abbreviations list when adding aliases + set -l alias_key + set -l alias_value + + # Parse args as `alias` options + argparse --name 'alias' --ignore-unknown 's/save' -- $command + + if string match -q '*=*' -- "$argv[2]" + if test (count $argv) = 2 + set command_split (string split '=' -- $argv[2]) + set alias_key "a__$command_split[1]" + set alias_value $command_split[2] + set -a alias_value $command[3..-1] + end + else + set alias_key "a__$argv[2]" + set alias_value $argv[3..-1] + end + + set alias_value (trim_value "$alias_value") + + if set -l abb (contains -i -- "$argv[3..-1]" $__ABBR_TIPS_KEYS) + set __ABBR_TIPS_KEYS[$abb] $alias_key + set __ABBR_TIPS_VALUES[$abb] $alias_value + else + set -a __ABBR_TIPS_KEYS $alias_key + set -a __ABBR_TIPS_VALUES $alias_value + end + else if test "$command[1]" = "functions" + # Parse args as `functions` options + argparse --name 'functions' 'e/erase' -- $command + + # Update abbreviations list when removing aliases + if set -q _flag_e + and set -l abb (contains -i -- a__{$argv[2]} $__ABBR_TIPS_KEYS) + set -e __ABBR_TIPS_KEYS[$abb] + set -e __ABBR_TIPS_VALUES[$abb] + end + end + + # Exit in the following cases : + # - abbreviation has been used + # - command is already an abbreviation + # - command not found + # - or it's a function (alias) + if test $__abbr_tips_used = 1 + set -g __abbr_tips_used 0 + return + else if abbr -q "$cmd" + or not type -q "$command[1]" + return + else if string match -q -- "alias $cmd *" (alias) + return + else if test (type -t "$command[1]") = 'function' + and count $ABBR_TIPS_ALIAS_WHITELIST >/dev/null + and not contains "$command[1]" $ABBR_TIPS_ALIAS_WHITELIST + return + end + + set -l abb + if not set abb (contains -i -- "$cmd" $__ABBR_TIPS_VALUES) + for r in $ABBR_TIPS_REGEXES + if set abb (contains -i -- (string replace -r -a -- "$r" '$1' "$cmd") $__ABBR_TIPS_VALUES) + break + end + end + end + + if test -n "$abb" + if string match -q "a__*" -- "$__ABBR_TIPS_KEYS[$abb]" + set -l alias (string sub -s 4 -- "$__ABBR_TIPS_KEYS[$abb]") + if functions -q "$alias" + echo -e (string replace -a '{{ .cmd }}' -- "$__ABBR_TIPS_VALUES[$abb]" \ + (string replace -a '{{ .abbr }}' -- "$alias" "$ABBR_TIPS_PROMPT")) + else + set -e __ABBR_TIPS_KEYS[$abb] + set -e __ABBR_TIPS_VALUES[$abb] + end + else + echo -e (string replace -a '{{ .cmd }}' -- "$__ABBR_TIPS_VALUES[$abb]" \ + (string replace -a '{{ .abbr }}' -- "$__ABBR_TIPS_KEYS[$abb]" "$ABBR_TIPS_PROMPT")) + end + end + + return +end + +function __abbr_tips_uninstall --on-event abbr_tips_uninstall + bind --erase \n + bind --erase \r + bind --erase " " + set --erase __abbr_tips_used + set --erase __abbr_tips_run_once + set --erase __ABBR_TIPS_VALUES + set --erase __ABBR_TIPS_KEYS + set --erase ABBR_TIPS_PROMPT + set --erase ABBR_TIPS_AUTO_UPDATE + set --erase ABBR_TIPS_ALIAS_WHITELIST + set --erase ABBR_TIPS_REGEXES + functions --erase __abbr_tips_init + functions --erase __abbr_tips_bind_newline + functions --erase __abbr_tips_bind_space + functions --erase __abbr_tips +end diff --git a/.config/fish/conf.d/fzf.fish b/.config/fish/conf.d/fzf.fish new file mode 100644 index 00000000..8156c11b --- /dev/null +++ b/.config/fish/conf.d/fzf.fish @@ -0,0 +1,28 @@ +# 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 +if not status is-interactive && test "$CI" != true + exit +end + +# Because of scoping rules, to capture the shell variables exactly as they are, we must read +# them before even executing _fzf_search_variables. We use psub to store the +# variables' info in temporary files and pass in the filenames as arguments. +# This variable is global so that it can be referenced by fzf_configure_bindings and in tests +set --global _fzf_search_vars_command '_fzf_search_variables (set --show | psub) (set --names | psub)' + + +# Install the default bindings, which are mnemonic and minimally conflict with fish's preset bindings +fzf_configure_bindings + +# Doesn't erase autoloaded _fzf_* functions because they are not easily accessible once key bindings are erased +function _fzf_uninstall --on-event fzf_uninstall + _fzf_uninstall_bindings + + set --erase _fzf_search_vars_command + functions --erase _fzf_uninstall _fzf_migration_message _fzf_uninstall_bindings fzf_configure_bindings + complete --erase fzf_configure_bindings + + set_color cyan + echo "fzf.fish uninstalled." + echo "You may need to manually remove fzf_configure_bindings from your config.fish if you were using custom key bindings." + set_color normal +end diff --git a/.config/fish/conf.d/halostatue_fish_docker.fish b/.config/fish/conf.d/halostatue_fish_docker.fish new file mode 100644 index 00000000..959da8d1 --- /dev/null +++ b/.config/fish/conf.d/halostatue_fish_docker.fish @@ -0,0 +1,31 @@ +function _halostatue_fish_docker_uninstall -e halostatue_fish_docker_uninstall + functions -e (functions -a | command awk '/_halostatue_fish_docker_/') +end + +function _halostatue_fish_docker_print_containers --description 'Print a list of docker containers' -a select append + set -l filter + switch $select + case running + set filter --filter status=running + case stopped + set filter --filter status=exited + case '*' + set filter --all + end + + test -z $append; and set append '' + + docker ps --no-trunc $filter --format '{{.ID}}\n{{.Names}}' | tr ',' $append'\n' +end + +function _halostatue_fish_docker_print_images --description 'Print a list of docker images' + docker images --format '{{if eq .Repository "<none>"}}{{.ID}}\tUnnamed Image{{else}}{{.Repository}}:{{.Tag}}{{end}}' +end + +function _halostatue_fish_docker_print_repositories --description 'Print a list of docker repositories' + docker images --format '{{.Repository}}' | command grep -v '<none>' | command sort | command uniq +end + +function _halostatue_fish_docker_print_compose_services --description 'Print a list of docker-compose services' + docker-compose config --services 2>/dev/null | command sort +end |