Skip to content

Instantly share code, notes, and snippets.

@britishtea
Last active April 5, 2016 01:03
Show Gist options
  • Save britishtea/d3e5cc5155194881d0fd to your computer and use it in GitHub Desktop.
Save britishtea/d3e5cc5155194881d0fd to your computer and use it in GitHub Desktop.
Bookmarking directories in the fish shell. Copy the file to $fish_function_path (~/.config/fish/functions by default) as jump.fish to install.
function jump -d "Jumps to a marked directory"
# If $JUMP_PATH isn't set, use a default (~/.config/jump).
if set -q $JUMP_PATH
set JUMP_PATH $HOME/.config/jump
end
# If the $JUMP_PATH directory doesn't exist, create it.
if not test -d $JUMP_PATH
mkdir -p $JUMP_PATH
end
# Print usage information if necessary
if begin; test (count $argv) -eq 0; or test $argv[1] = "-h"; end
echo "Usage: jump option"
echo " jump <bookmark name> [sub directory]"
echo
echo "Options:"
echo
echo " -m NAME bookmarks a directory as NAME"
echo " -d NAME removes a bookmarked directory NAME"
echo " -h display this help message"
echo
echo "Bookmarks:"
echo
ls -l $JUMP_PATH | grep " -> " | sed 's/ / /g' | cut -d' ' -f9-
return
end
# Adding bookmarks
if test $argv[1] = "-m"
if test (count $argv) -eq 2
ln -s $PWD $JUMP_PATH/$argv[2]
return $status
else
echo "no bookmark name given"
return 1
end
end
# Removing bookmarks
if test $argv[1] = "-d"
if test (count $argv) -eq 2
rm -f $JUMP_PATH/$argv[2]
return $status
else
echo "no bookmark name given"
return 1
end
end
# Switching directories
if test -L $JUMP_PATH/$argv[1]
cd $JUMP_PATH/$argv[1]
if test (count $argv) -eq 2
cd $argv[2]
end
return 0
else
echo "no such bookmark: $argv[1]"
return 2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment