#!/bin/zsh # check if no arguments if [[ -z "$1" ]]; then # save output of a command into a variable answer=$(skate list @j | gum choose) # split answer on tabs and take the first part key=$(echo $answer | cut -f1) mypath=$(skate get $key"@j") # if path is not equal to Key cannot be empty if [[ $mypath != "Key cannot be empty" ]]; then echo $mypath fi else # if there is one argument check if it's a number if [[ $1 =~ ^[0-9]+$ ]]; then answer=$(skate get $1"@j") # if the answer is not equal to Key not found if [[ $answer != "Key not found" ]]; then echo "$answer" else >&2 echo "Bookmark not found" fi else # check if the first argument is set or delete if [[ $1 == "set" ]]; then # check if there are two arguments if [[ $# -eq 2 ]]; then #check if the second argument is a number between 0 and 9 if [[ $2 =~ ^[0-9]$ ]]; then skate set $2"@j" $(pwd) else >&2 echo "Bookmark must be a number between 0 and 9" fi else >&2 echo "Usage: j set [0-9]" fi elif [[ $1 == "delete" ]]; then # check if there are two arguments if [[ $# -eq 2 ]]; then # check if the second argument is a number between 0 and 9 if [[ $2 =~ ^[0-9]$ ]]; then mypath=$(skate get $2"@j") 2> /dev/null if [[ ! -z $mypath ]]; then >&2 gum style --foreground=212 "Deleting bookmark: $2 $mypath" gum confirm && skate delete $2"@j" else >&2 echo "Bookmark not found" fi else >&2 echo "Bookmark must be a number between 0 and 9" fi else >&2 echo "Usage: j delete [0-9]" fi else >&2 echo "Usage: j [set|delete] [0-9]" fi fi fi