#W# Initial Commit: No Flake Config
This commit is contained in:
commit
c463cec3e2
74 changed files with 14898 additions and 0 deletions
78
home/config/fish/functions/goto.fish
Normal file
78
home/config/fish/functions/goto.fish
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
function goto
|
||||
set -l gotoConfig "$HOME/.config/goto/bookmarks"
|
||||
set -l gotoDir "$HOME/.config/goto"
|
||||
mkdir -p "$gotoDir"
|
||||
touch "$gotoConfig"
|
||||
|
||||
set -l command $argv[1]
|
||||
set -l bookmark_name $argv[2]
|
||||
|
||||
if test -z "$command"
|
||||
echo "Usage: goto s <name> (save current directory)"
|
||||
echo " goto g <name> (go to saved directory)"
|
||||
echo " goto d <name> (delete a bookmark)"
|
||||
echo " goto l (list all bookmarks)"
|
||||
echo " goto e (edit bookmarks file)"
|
||||
return
|
||||
end
|
||||
|
||||
switch $command
|
||||
case s # Save bookmarks
|
||||
if test -z "$bookmark_name"
|
||||
echo "Error: Must provide a bookmark name to save."
|
||||
return 1
|
||||
end
|
||||
sed -i "/^$bookmark_name:/d" "$gotoConfig"
|
||||
echo "$bookmark_name:"(pwd) >> "$gotoConfig"
|
||||
echo "Bookmark $bookmark_name saved to: "(pwd)
|
||||
|
||||
case g # Go to bookmark
|
||||
if test -z "$bookmark_name"
|
||||
echo "Error: Must provide a bookmark name to go to."
|
||||
return 1
|
||||
end
|
||||
set -l target_path (grep "^$bookmark_name:" "$gotoConfig" | cut -d ':' -f 2)
|
||||
if test -z "$target_path"
|
||||
echo "Error: Bookmark $bookmark_name not found."
|
||||
return 1
|
||||
end
|
||||
if test -d "$target_path"
|
||||
cd "$target_path"
|
||||
echo "Jumping to: $target_path"
|
||||
else
|
||||
echo "Error: Directory $target_path does not exist or is not a directory"
|
||||
end
|
||||
|
||||
case d # Delete bookmark
|
||||
if test -z "$bookmark_name"
|
||||
echo "Error: Must provide a bookmark name to delete."
|
||||
return 1
|
||||
end
|
||||
if grep -q "^$bookmark_name:" "$gotoConfig"
|
||||
sed -i "/^$bookmark_name:/d" "$gotoConfig"
|
||||
echo "Bookmark $bookmark_name deleted."
|
||||
else
|
||||
echo "Error: Bookmark $bookmark_name not found."
|
||||
return 1
|
||||
end
|
||||
|
||||
case e # Edit bookmarks file
|
||||
if set -q EDITOR
|
||||
$EDITOR "$gotoConfig"
|
||||
else
|
||||
nano "$gotoConfig"
|
||||
end
|
||||
|
||||
case l # List bookmarks
|
||||
if not test -s "$gotoConfig"
|
||||
echo "No bookmarks saved yet."
|
||||
return 0
|
||||
end
|
||||
echo "___ Bookmarks (Stored in: $gotoDir) ___"
|
||||
column -t -s ':' "$gotoConfig"
|
||||
|
||||
case '*'
|
||||
echo "Invalid command: $command"
|
||||
goto # Show usage
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue