Skip to content

Instantly share code, notes, and snippets.

@lengyijun
Created January 10, 2025 00:30
auto cd after git clone <url>
function auto_cd_xdotool --on-event fish_prompt
if test $status -eq 0
if string match -q "mkdir*" $history[1]
set -l splits (string split -n ' ' $history[1])
for i in $splits[-1..2]
if not string match -q -- "-*" $i
xdotool type --delay 100 "cd $i"
return
end
end
end
if string match -q "git clone*" $history[1]
set -l splits (string split -n ' ' $history[1])
for i in $splits[-1..3]
if string match -q "https://*" $i
set -l split1 (string split -n '/' $i)
xdotool type --delay 100 "cd $split1[-1]"
return
end
if string match -q "git@*.git" $i
set -l last (string split '/' $i)[-1]
set -l dir_name (string sub --end -4 $last)
xdotool type --delay 100 "cd $dir_name"
return
end
if not string match -q -- "-*" $i
xdotool type --delay 100 "cd $i"
return
end
end
end
end
end
@lengyijun
Copy link
Author

Put this fn in ~/.config/fish/config.fish

@lengyijun
Copy link
Author

Cons

  • not work in ssh
  • not work in wayland

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment