From 2a1053330b41324ce5452f9390f508c5bd419cbb Mon Sep 17 00:00:00 2001 From: Andre Ramnitz Date: Thu, 17 Jul 2025 18:28:06 +0200 Subject: [PATCH] fish: update aliases/functions --- dot-config/fish/completions/lf.fish | 24 ++++++++++++++++++++++++ dot-config/fish/fish_variables | 2 +- dot-config/fish/functions/cdg.fish | 4 ++++ dot-config/fish/functions/lfcd.fish | 19 +++++++++++++++++++ dot-config/fish/functions/y.fish | 9 +++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 dot-config/fish/completions/lf.fish create mode 100644 dot-config/fish/functions/cdg.fish create mode 100644 dot-config/fish/functions/lfcd.fish create mode 100644 dot-config/fish/functions/y.fish diff --git a/dot-config/fish/completions/lf.fish b/dot-config/fish/completions/lf.fish new file mode 100644 index 00000000..ff8d7858 --- /dev/null +++ b/dot-config/fish/completions/lf.fish @@ -0,0 +1,24 @@ +# Autocompletion for fish shell. +# +# You may put this file to a directory in $fish_complete_path variable: +# +# mkdir -p ~/.config/fish/completions +# ln -s "/path/to/lf.fish" ~/.config/fish/completions +# + +complete -c lf -o command -r -d 'command to execute on client initialization' +complete -c lf -o config -r -d 'path to the config file (instead of the usual paths)' +complete -c lf -o cpuprofile -r -d 'path to the file to write the CPU profile' +complete -c lf -o doc -d 'show documentation' +complete -c lf -o last-dir-path -r -d 'path to the file to write the last dir on exit (to use for cd)' +complete -c lf -o log -r -d 'path to the log file to write messages' +complete -c lf -o memprofile -r -d 'path to the file to write the memory profile' +complete -c lf -o print-last-dir -d 'print the last dir to stdout on exit (to use for cd)' +complete -c lf -o print-selection -d 'print the selected files to stdout on open (to use as open file dialog)' +complete -c lf -o remote -x -d 'send remote command to server' +complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)' +complete -c lf -o server -d 'start server (automatic)' +complete -c lf -o single -d 'start a client without server' +complete -c lf -o version -d 'show version' +complete -c lf -o help -d 'show help' + diff --git a/dot-config/fish/fish_variables b/dot-config/fish/fish_variables index eb042f1a..43b67554 100644 --- a/dot-config/fish/fish_variables +++ b/dot-config/fish/fish_variables @@ -29,4 +29,4 @@ SETUVAR fish_pager_color_description:yellow\x1e\x2di SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan SETUVAR fish_pager_color_selected_background:\x2dr -SETUVAR fish_user_paths:/home/andy/Applications\x1e/home/andy/go/bin\x1e/home/andy/\x2ecargo/bin\x1e/home/andy/\x2elocal/bin\x1e/home/andy/\x2espicetify +SETUVAR fish_user_paths:/media/source/dart\x2dsass\x1e/home/andy/Applications\x1e/home/andy/go/bin\x1e/home/andy/\x2ecargo/bin\x1e/home/andy/\x2elocal/bin\x1e/home/andy/\x2espicetify diff --git a/dot-config/fish/functions/cdg.fish b/dot-config/fish/functions/cdg.fish new file mode 100644 index 00000000..59cfe11b --- /dev/null +++ b/dot-config/fish/functions/cdg.fish @@ -0,0 +1,4 @@ +function cdg --wraps='cd (git rev-parse --show-toplevel)' --description 'alias cdg cd (git rev-parse --show-toplevel)' + cd (git rev-parse --show-toplevel) $argv + +end diff --git a/dot-config/fish/functions/lfcd.fish b/dot-config/fish/functions/lfcd.fish new file mode 100644 index 00000000..1e50b6fe --- /dev/null +++ b/dot-config/fish/functions/lfcd.fish @@ -0,0 +1,19 @@ +# Change working dir in fish to last dir in lf on exit (adapted from ranger). +# +# You may put this file to a directory in $fish_function_path variable: +# +# mkdir -p ~/.config/fish/functions +# ln -s "/path/to/lfcd.fish" ~/.config/fish/functions +# +# You may also like to assign a key (Ctrl-O) to this command: +# +# bind \co 'set old_tty (stty -g); stty sane; lfcd; stty $old_tty; commandline -f repaint' +# +# You may put this in a function called fish_user_key_bindings. + +function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)" + # `command` is needed in case `lfcd` is aliased to `lf`. + # Quotes will cause `cd` to not change directory if `lf` prints nothing to stdout due to an error. + cd "$(command lf -print-last-dir $argv)" +end + diff --git a/dot-config/fish/functions/y.fish b/dot-config/fish/functions/y.fish new file mode 100644 index 00000000..8d6d44af --- /dev/null +++ b/dot-config/fish/functions/y.fish @@ -0,0 +1,9 @@ +function y + set tmp (mktemp -t "yazi-cwd.XXXXXX") + yazi $argv --cwd-file="$tmp" + if read -z cwd < "$tmp"; and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ] + builtin cd -- "$cwd" + end + rm -f -- "$tmp" +end + -- 2.51.2