From ddaa5013d523942fb1429c4c7f6f2ac9f841a89d Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 22 Jan 2025 21:08:34 +0100 Subject: common/fish: implement sll function and command path shortcut --- common/commandline/fish.fish | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'common/commandline') diff --git a/common/commandline/fish.fish b/common/commandline/fish.fish index 294849c..828d56f 100644 --- a/common/commandline/fish.fish +++ b/common/commandline/fish.fish @@ -5,12 +5,41 @@ set -g fish_key_bindings fish_vi_key_bindings bind -M insert ctrl-Z 'fg ; commandline -f repaint' function ssht - ssh -t "$argv" "tmux new-session -A -s 'ssh-$HOST'" + ssh -t "$argv" "tmux new-session -A -s 'ssh-$HOST'" end function cdt - builtin cd (mktemp -d) - builtin pwd + builtin cd (mktemp -d) + builtin pwd end -# TODO: sll +function sll --description "Recursively resolve a symbolic link" + for path in $argv + set -l seen_inodes + + while test -L $path + set inode (stat -c %i $path) + + if contains $inode $seen_inodes + echo "Infinite recursion detected" + return 1 + end + set -a seen_inodes $inode + + ll -d $path || return 1 + + set previous_dir (path dirname $path) + set path (readlink $path | path normalize) + if not string match -q "/*" $path + set path (path normalize "$previous_dir/$path") + end + end + ll -d $path || return 1 + end +end + +function expand_equal_command + type -P (string sub --start 2 $argv) +end + +abbr -a expand_equal_command --position anywhere --regex "^=.+" --function expand_equal_command -- cgit v1.2.3