From abad2d257c1fcdea72135c874fce6a5961d53fce Mon Sep 17 00:00:00 2001 From: Raphael Eguchi Date: Sun, 26 Jan 2025 22:13:23 -0500 Subject: [PATCH] modified names for better namespace safety --- src/add_bookmark.sh | 26 ++++---- src/clear_bookmarks.sh | 14 ++-- src/colors.sh | 12 ++-- src/functions.sh | 146 ++++++++++++++++++++--------------------- src/go_to_bookmark.sh | 46 ++++++------- src/jump_to_child.sh | 22 +++---- src/jump_to_parent.sh | 34 +++++----- src/list_bookmarks.sh | 20 +++--- src/remove_bookmark.sh | 42 ++++++------ 9 files changed, 181 insertions(+), 181 deletions(-) diff --git a/src/add_bookmark.sh b/src/add_bookmark.sh index 0d744f9..9cb8a83 100755 --- a/src/add_bookmark.sh +++ b/src/add_bookmark.sh @@ -1,32 +1,32 @@ #!/bin/bash # Imports. -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$SCRIPT_DIR"/colors.sh -source "$SCRIPT_DIR"/functions.sh +SHUNPO_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SHUNPO_SCRIPT_DIR"/colors.sh +source "$SHUNPO_SCRIPT_DIR"/functions.sh # File to store bookmarks. -MAX_BOOKMARKS=128 +SHUNPO_MAX_BOOKMARKS=128 # Ensure the bookmarks file exists and is not empty -if [ ! -f "$BOOKMARKS_FILE" ]; then - touch "$BOOKMARKS_FILE" +if [ ! -f "$SHUNPO_BOOKMARKS_FILE" ]; then + touch "$SHUNPO_BOOKMARKS_FILE" fi # Check the number of existing bookmarks. -current_bookmarks=$(wc -l <"$BOOKMARKS_FILE") +current_bookmarks=$(wc -l <"$SHUNPO_BOOKMARKS_FILE") # If the bookmarks list is full, print a message and do not add the new bookmark. -if [ "$current_bookmarks" -ge "$MAX_BOOKMARKS" ]; then - echo -e "${CYAN}${BOLD}Bookmarks list is full!${RESET} Maximum of $MAX_BOOKMARKS bookmarks allowed." +if [ "$current_bookmarks" -ge "$SHUNPO_MAX_BOOKMARKS" ]; then + echo -e "${SHUNPO_CYAN}${SHUNPO_BOLD}Bookmarks list is full!${SHUNPO_RESET} Maximum of $SHUNPO_MAX_BOOKMARKS bookmarks allowed." exit 1 fi # Save the current directory to the bookmarks file. current_dir=$(realpath "$PWD") -if ! grep -q -x "$(printf '%s\n' "$current_dir")" "$BOOKMARKS_FILE"; then - echo "$current_dir" >>"$BOOKMARKS_FILE" - echo -e "${GREEN}${BOLD}Bookmark added:${RESET} $current_dir" +if ! grep -q -x "$(printf '%s\n' "$current_dir")" "$SHUNPO_BOOKMARKS_FILE"; then + echo "$current_dir" >>"$SHUNPO_BOOKMARKS_FILE" + echo -e "${SHUNPO_GREEN}${SHUNPO_BOLD}Bookmark added:${SHUNPO_RESET} $current_dir" else - echo -e "${ORANGE}${BOLD}Bookmark exists:${RESET} $current_dir" + echo -e "${SHUNPO_ORANGE}${SHUNPO_BOLD}Bookmark exists:${SHUNPO_RESET} $current_dir" fi diff --git a/src/clear_bookmarks.sh b/src/clear_bookmarks.sh index 9b64a1f..fff45c6 100755 --- a/src/clear_bookmarks.sh +++ b/src/clear_bookmarks.sh @@ -1,16 +1,16 @@ #!/bin/bash # Colors and formatting. -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$SCRIPT_DIR"/colors.sh -source "$SCRIPT_DIR"/functions.sh +SHUNPO_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SHUNPO_SCRIPT_DIR"/colors.sh +source "$SHUNPO_SCRIPT_DIR"/functions.sh # Remove the bookmarks file if it exists. -if [ ! -f "$BOOKMARKS_FILE" ] || [ ! -s "$BOOKMARKS_FILE" ]; then - echo -e "${ORANGE}${BOLD}No Bookmarks Found.${RESET}" +if [ ! -f "$SHUNPO_BOOKMARKS_FILE" ] || [ ! -s "$SHUNPO_BOOKMARKS_FILE" ]; then + echo -e "${SHUNPO_ORANGE}${SHUNPO_BOLD}No Bookmarks Found.${SHUNPO_RESET}" exit 1 else - rm "$BOOKMARKS_FILE" - echo -e "${RED}${BOLD}Cleared Bookmarks.${RESET}" + rm "$SHUNPO_BOOKMARKS_FILE" + echo -e "${SHUNPO_RED}${SHUNPO_BOLD}Cleared Bookmarks.${SHUNPO_RESET}" fi diff --git a/src/colors.sh b/src/colors.sh index 1db4bd0..bf2076c 100644 --- a/src/colors.sh +++ b/src/colors.sh @@ -1,7 +1,7 @@ #!/bin/bash -CYAN='\033[36m' -ORANGE='\033[38;5;208m' -GREEN='\033[38;5;43m' -RED='\033[38;5;203m' -BOLD='\033[1m' -RESET='\033[0m' +SHUNPO_CYAN='\033[36m' +SHUNPO_ORANGE='\033[38;5;208m' +SHUNPO_GREEN='\033[38;5;43m' +SHUNPO_RED='\033[38;5;203m' +SHUNPO_BOLD='\033[1m' +SHUNPO_RESET='\033[0m' diff --git a/src/functions.sh b/src/functions.sh index 5d33b8c..1292018 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -1,10 +1,10 @@ #!/bin/bash # Default Bookmarks Path. -BOOKMARKS_FILE="$HOME/.shunpo_bookmarks" +SHUNPO_BOOKMARKS_FILE="$HOME/.shunpo_bookmarks" # Function to display bookmarks with pagination. -function interact_bookmarks() { +function shunpo_interact_bookmarks() { local bookmarks=() local total_bookmarks local current_page=0 @@ -19,23 +19,23 @@ function interact_bookmarks() { # Read bookmarks into an array. while IFS= read -r bookmark; do bookmarks+=("$bookmark") - done <"$BOOKMARKS_FILE" + done <"$SHUNPO_BOOKMARKS_FILE" # Check that bookmarks file is not empty. total_bookmarks=${#bookmarks[@]} if [ "$total_bookmarks" -eq 0 ]; then - echo -e "${BOLD}${ORANGE}No Bookmarks Found.${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}No Bookmarks Found.${SHUNPO_RESET}" return 0 fi # If a selection is specified, select it. if [ -n "$2" ]; then if ! [[ $2 =~ ^[0-9]+$ ]]; then - echo -e "${BOLD}${ORANGE}Invalid Bookmark Selection.${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}Invalid Bookmark Selection.${SHUNPO_RESET}" return 1 else if [[ $2 -lt $total_bookmarks ]]; then - selected_dir="${bookmarks[$2]}" + shunpo_selected_dir="${bookmarks[$2]}" tput cnorm return 0 else @@ -68,18 +68,18 @@ function interact_bookmarks() { fi padding_lines=$((padding_lines + 1)) # header. - add_space $padding_lines + shunpo_add_space $padding_lines tput sc - echo -e "${BOLD}${CYAN}Shunpo <$1>${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_CYAN}Shunpo <$1>${SHUNPO_RESET}" # Display bookmarks for the current page. for ((i = start_index; i < end_index; i++)); do - echo -e "[${BOLD}${ORANGE}$((i - start_index))${RESET}] ${bookmarks[i]}" + echo -e "[${SHUNPO_BOLD}${SHUNPO_ORANGE}$((i - start_index))${SHUNPO_RESET}] ${bookmarks[i]}" done if [ $last_page -gt 1 ]; then - echo -e "${CYAN}[$((current_page + 1)) / $((last_page))]${RESET}" + echo -e "${SHUNPO_CYAN}[$((current_page + 1)) / $((last_page))]${SHUNPO_RESET}" fi # Read input to select bookmarks and cycle through pages. @@ -88,37 +88,37 @@ function interact_bookmarks() { if [ $((current_page + 1)) -le $((last_page - 1)) ]; then current_page=$((current_page + 1)) fi - clear_output + shunpo_clear_output elif [[ $input == "p" ]]; then if [ $((current_page - 1)) -ge 0 ]; then current_page=$((current_page - 1)) fi - clear_output + shunpo_clear_output elif [[ $input =~ ^[0-9]+$ ]] && [ "$input" -ge 0 ] && [ "$input" -lt $max_per_page ]; then # Process bookmark selection input. - selected_bookmark_index=$((current_page * max_per_page + input)) - if [[ $selected_bookmark_index -lt $total_bookmarks ]]; then - selected_dir="${bookmarks[$selected_bookmark_index]}" - clear_output + shunpo_selected_bookmark_index=$((current_page * max_per_page + input)) + if [[ $shunpo_selected_bookmark_index -lt $total_bookmarks ]]; then + shunpo_selected_dir="${bookmarks[$shunpo_selected_bookmark_index]}" + shunpo_clear_output tput cnorm return 0 else - clear_output + shunpo_clear_output fi else - clear_output + shunpo_clear_output tput cnorm return 0 fi done - clear_output + shunpo_clear_output tput cnorm return 0 } -function jump_to_parent_dir() { +function shunpo_jump_to_parent_dir() { local current_dir=$(pwd) local max_levels=128 local parent_dirs=() @@ -142,7 +142,7 @@ function jump_to_parent_dir() { # Check if we are at the root. if [[ ${#parent_dirs[@]} -eq 1 && ${parent_dirs[0]} == "/" ]]; then - echo -e "${BOLD}${ORANGE}No Parent Directories.${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}No Parent Directories.${SHUNPO_RESET}" return 1 fi @@ -151,13 +151,13 @@ function jump_to_parent_dir() { # If a selection is specified, select it. if [ -n "$1" ]; then if ! [[ $1 =~ ^[0-9]+$ ]]; then - echo -e "${BOLD}${ORANGE}Invalid Parent Selection.${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}Invalid Parent Selection.${SHUNPO_RESET}" return 1 else if [[ $1 -lt $total_parents ]]; then cd "${parent_dirs[$1]}" || exit tput cnorm - echo -e "${GREEN}${BOLD}Changed to:${RESET} ${parent_dirs[$1]}" + echo -e "${SHUNPO_GREEN}${SHUNPO_BOLD}Changed to:${SHUNPO_RESET} ${parent_dirs[$1]}" return 0 else tput cnorm @@ -188,18 +188,18 @@ function jump_to_parent_dir() { fi padding_lines=$((padding_lines + 1)) # header. - add_space $padding_lines + shunpo_add_space $padding_lines tput sc - echo -e "${BOLD}${CYAN}Shunpo ${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_CYAN}Shunpo ${SHUNPO_RESET}" # Display the current page of parent directories. for ((i = start_index; i < end_index; i++)); do - echo -e "[${BOLD}${ORANGE}$((i - start_index))${RESET}] ${parent_dirs[i]}" + echo -e "[${SHUNPO_BOLD}${SHUNPO_ORANGE}$((i - start_index))${SHUNPO_RESET}] ${parent_dirs[i]}" done if [ $last_page -gt 1 ]; then - echo -e "${CYAN}[$((current_page + 1)) / $last_page]${RESET}" + echo -e "${SHUNPO_CYAN}[$((current_page + 1)) / $last_page]${SHUNPO_RESET}" fi # Read and process user input. @@ -208,37 +208,37 @@ function jump_to_parent_dir() { if [ $((current_page + 1)) -lt "$last_page" ]; then current_page=$((current_page + 1)) fi - clear_output + shunpo_clear_output elif [[ $input == "p" ]]; then if [ $((current_page - 1)) -ge 0 ]; then current_page=$((current_page - 1)) fi - clear_output + shunpo_clear_output elif [[ $input =~ ^[0-9]+$ ]] && [ "$input" -gt 0 ] && [ "$input" -le "$max_per_page" ]; then selected_index=$((start_index + input)) if [[ $selected_index -lt $total_parents ]]; then - clear_output + shunpo_clear_output tput cnorm cd "${parent_dirs[$selected_index]}" || exit - echo -e "${GREEN}${BOLD}Changed to:${RESET} ${parent_dirs[$selected_index]}" + echo -e "${SHUNPO_GREEN}${SHUNPO_BOLD}Changed to:${SHUNPO_RESET} ${parent_dirs[$selected_index]}" return 0 else - clear_output + shunpo_clear_output fi else - clear_output + shunpo_clear_output tput cnorm return 0 fi done - clear_output + shunpo_clear_output tput cnorm return 0 } -function jump_to_child_dir() { +function shunpo_jump_to_child_dir() { local current_dir=$(pwd) local max_per_page=10 local current_page=0 @@ -259,7 +259,7 @@ function jump_to_child_dir() { local cache_keys=() local cache_values=() - function is_cached() { + function shunpo_is_cached() { local path="$1" for i in "${!cache_keys[@]}"; do if [[ ${cache_keys[$i]} == "$path" ]]; then @@ -272,7 +272,7 @@ function jump_to_child_dir() { while true; do # Attempt to retrieve from cache. - if cache_index=$(is_cached "$selected_path"); then + if cache_index=$(shunpo_is_cached "$selected_path"); then # Use cached value. IFS='|' read -r -a child_dirs <<<"${cache_values[$cache_index]}" else @@ -312,35 +312,35 @@ function jump_to_child_dir() { fi padding_lines=$((padding_lines + 2)) # header and selected path. - add_space $padding_lines + shunpo_add_space $padding_lines tput sc - echo -e "${BOLD}${CYAN}Shunpo ${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_CYAN}Shunpo ${SHUNPO_RESET}" # Print selected path and options. if [[ $is_start_dir -eq 1 ]]; then - echo -e "Selected Path: ${CYAN}$selected_path${RESET} ${ORANGE}(Initial)${RESET}" + echo -e "Selected Path: ${SHUNPO_CYAN}$selected_path${SHUNPO_RESET} ${SHUNPO_ORANGE}(Initial)${SHUNPO_RESET}" else - echo -e "Selected Path: ${CYAN}$selected_path${RESET}" + echo -e "Selected Path: ${SHUNPO_CYAN}$selected_path${SHUNPO_RESET}" fi if [[ $total_child_dirs -eq 0 ]]; then if [[ $is_start_dir -eq 1 ]]; then - clear_output - echo -e "${BOLD}${ORANGE}No Child Directories.${RESET}" + shunpo_clear_output + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}No Child Directories.${SHUNPO_RESET}" tput cnorm return 1 else - echo -e "${BOLD}${ORANGE}No Child Directories.${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}No Child Directories.${SHUNPO_RESET}" fi else # Print child directories. for ((i = start_index; i < end_index; i++)); do - echo -e "[${BOLD}${ORANGE}$((i - start_index))${RESET}] ${child_dirs[i]#$selected_path}" + echo -e "[${SHUNPO_BOLD}${SHUNPO_ORANGE}$((i - start_index))${SHUNPO_RESET}] ${child_dirs[i]#$selected_path}" done if [ $last_page -gt 1 ]; then - echo -e "${CYAN}[$((current_page + 1)) / $last_page]${RESET}" + echo -e "${SHUNPO_CYAN}[$((current_page + 1)) / $last_page]${SHUNPO_RESET}" fi fi @@ -350,17 +350,17 @@ function jump_to_child_dir() { if [ $((current_page + 1)) -lt "$last_page" ]; then current_page=$((current_page + 1)) fi - clear_output + shunpo_clear_output elif [[ $input == "p" ]]; then if [ $((current_page - 1)) -ge 0 ]; then current_page=$((current_page - 1)) fi - clear_output + shunpo_clear_output elif [[ $input == "b" ]]; then if [[ $is_start_dir -eq 1 ]]; then - clear_output + shunpo_clear_output continue else selected_path=$(realpath "$selected_path/../") @@ -372,13 +372,13 @@ function jump_to_child_dir() { is_start_dir=0 fi current_page=0 - clear_output + shunpo_clear_output elif [[ $input == "" ]]; then - clear_output + shunpo_clear_output if [[ $is_start_dir -ne 1 ]]; then cd "$selected_path" || exit - echo -e "${GREEN}${BOLD}Changed to:${RESET} $selected_path" + echo -e "${SHUNPO_GREEN}${SHUNPO_BOLD}Changed to:${SHUNPO_RESET} $selected_path" fi break @@ -389,10 +389,10 @@ function jump_to_child_dir() { is_start_dir=0 current_page=0 fi - clear_output + shunpo_clear_output else - clear_output + shunpo_clear_output tput cnorm break fi @@ -403,7 +403,7 @@ function jump_to_child_dir() { # Function to open several lines of space before writing when near the end of the terminal # to avoid visual issues. -function add_space() { +function shunpo_add_space() { # Get total terminal lines. total_lines=$(tput lines) @@ -421,35 +421,35 @@ function add_space() { tput ed } -function clear_output() { +function shunpo_clear_output() { tput rc # Restore saved cursor position. tput ed # Clear everything below the cursor. } -function assert_bookmarks_exist() { +function shunpo_assert_bookmarks_exist() { # Ensure the bookmarks file exists and is not empty. - if [ ! -f "$BOOKMARKS_FILE" ] || [ ! -s "$BOOKMARKS_FILE" ]; then - echo -e "${ORANGE}${BOLD}No Bookmarks Found.${RESET}" - cleanup + if [ ! -f "$SHUNPO_BOOKMARKS_FILE" ] || [ ! -s "$SHUNPO_BOOKMARKS_FILE" ]; then + echo -e "${SHUNPO_ORANGE}${SHUNPO_BOLD}No Bookmarks Found.${SHUNPO_RESET}" + shunpo_cleanup return 1 fi } -function cleanup() { +function shunpo_cleanup() { # Clean up to avoid namespace pollution. - unset BOOKMARKS_FILE + unset SHUNPO_BOOKMARKS_FILE unset IFS - unset selected_dir - unset selected_bookmark_index - unset -f interact_bookmarks - unset -f add_space - unset -f clear_output - unset -f assert_bookmarks_exist - unset -f jump_to_parent_dir - unset -f jump_to_child_dir - unset -f is_cached - unset -f handle_kill - unset -f cleanup + unset shunpo_selected_dir + unset shunpo_selected_bookmark_index + unset -f shunpo_interact_bookmarks + unset -f shunpo_add_space + unset -f shunpo_clear_output + unset -f shunpo_assert_bookmarks_exist + unset -f shunpo_jump_to_parent_dir + unset -f shunpo_jump_to_child_dir + unset -f shunpo_is_cached + unset -f shunpo_handle_kill + unset -f shunpo_cleanup tput cnorm stty echo trap - SIGINT diff --git a/src/go_to_bookmark.sh b/src/go_to_bookmark.sh index dc3658a..f1aa2ff 100755 --- a/src/go_to_bookmark.sh +++ b/src/go_to_bookmark.sh @@ -3,50 +3,50 @@ # This script should be sourced and not executed. # Colors and formatting. -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$SCRIPT_DIR"/colors.sh -source "$SCRIPT_DIR"/functions.sh - -function handle_kill() { - clear_output - if declare -f cleanup >/dev/null; then - cleanup +SHUNPO_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SHUNPO_SCRIPT_DIR"/colors.sh +source "$SHUNPO_SCRIPT_DIR"/functions.sh + +function shunpo_handle_kill() { + shunpo_clear_output + if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi return 1 } -trap 'handle_kill; return 1' SIGINT +trap 'shunpo_handle_kill; return 1' SIGINT -if ! assert_bookmarks_exist; then +if ! shunpo_assert_bookmarks_exist; then return 1 fi -interact_bookmarks "Go To Bookmark" "$1" +shunpo_interact_bookmarks "Go To Bookmark" "$1" # Handle case where bookmark is not set. if [ $? -eq 2 ]; then - if declare -f cleanup >/dev/null; then - cleanup + if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi - echo -e "${BOLD}${ORANGE}Bookmark is Empty.${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}Bookmark is Empty.${SHUNPO_RESET}" return 1 fi -if [[ -z $selected_dir ]]; then - if declare -f cleanup >/dev/null; then - cleanup +if [[ -z $shunpo_selected_dir ]]; then + if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi return 1 -elif [[ -d $selected_dir ]]; then - if cd "$selected_dir"; then - echo -e "${GREEN}${BOLD}Changed to:${RESET} $selected_dir" +elif [[ -d $shunpo_selected_dir ]]; then + if cd "$shunpo_selected_dir"; then + echo -e "${SHUNPO_GREEN}${SHUNPO_BOLD}Changed to:${SHUNPO_RESET} $shunpo_selected_dir" else - echo -e "${RED}${BOLD}Directory does not exist:${RESET} $selected_dir" + echo -e "${SHUNPO_RED}${SHUNPO_BOLD}Directory does not exist:${SHUNPO_RESET} $shunpo_selected_dir" fi else - echo -e "${RED}${BOLD}Directory does not exist:${RESET} $selected_dir" + echo -e "${SHUNPO_RED}${SHUNPO_BOLD}Directory does not exist:${SHUNPO_RESET} $shunpo_selected_dir" fi -cleanup +shunpo_cleanup diff --git a/src/jump_to_child.sh b/src/jump_to_child.sh index eb3bda1..9a906e1 100755 --- a/src/jump_to_child.sh +++ b/src/jump_to_child.sh @@ -2,21 +2,21 @@ # This script should be sourced and not executed. -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$SCRIPT_DIR"/colors.sh -source "$SCRIPT_DIR"/functions.sh +SHUNPO_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SHUNPO_SCRIPT_DIR"/colors.sh +source "$SHUNPO_SCRIPT_DIR"/functions.sh -function handle_kill() { - clear_output - if declare -f cleanup >/dev/null; then - cleanup +function shunpo_handle_kill() { + shunpo_clear_output + if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi return 0 } -trap 'handle_kill; return 1' SIGINT +trap 'shunpo_handle_kill; return 1' SIGINT -jump_to_child_dir -if declare -f cleanup >/dev/null; then - cleanup +shunpo_jump_to_child_dir +if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi diff --git a/src/jump_to_parent.sh b/src/jump_to_parent.sh index 6c127a5..19e0313 100755 --- a/src/jump_to_parent.sh +++ b/src/jump_to_parent.sh @@ -2,37 +2,37 @@ # This script should be sourced and not executed. -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$SCRIPT_DIR"/colors.sh -source "$SCRIPT_DIR"/functions.sh - -function handle_kill() { - clear_output - if declare -f cleanup >/dev/null; then - cleanup +SHUNPO_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SHUNPO_SCRIPT_DIR"/colors.sh +source "$SHUNPO_SCRIPT_DIR"/functions.sh + +function shunpo_handle_kill() { + shunpo_clear_output + if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi return 1 } -trap 'handle_kill; return 1' SIGINT +trap 'shunpo_handle_kill; return 1' SIGINT -jump_to_parent_dir $1 +shunpo_jump_to_parent_dir $1 # Handle case where bookmark is not set. if [ $? -eq 1 ]; then - if declare -f cleanup >/dev/null; then - cleanup + if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi return 1 elif [ $? -eq 2 ]; then - if declare -f cleanup >/dev/null; then - cleanup + if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi - echo -e "${BOLD}${ORANGE}Invalid Parent Selection.${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}Invalid Parent Selection.${SHUNPO_RESET}" return 1 fi -if declare -f cleanup >/dev/null; then - cleanup +if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi diff --git a/src/list_bookmarks.sh b/src/list_bookmarks.sh index e419138..fa15102 100755 --- a/src/list_bookmarks.sh +++ b/src/list_bookmarks.sh @@ -1,21 +1,21 @@ #!/bin/bash # Colors and formatting -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$SCRIPT_DIR"/colors.sh -source "$SCRIPT_DIR"/functions.sh +SHUNPO_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SHUNPO_SCRIPT_DIR"/colors.sh +source "$SHUNPO_SCRIPT_DIR"/functions.sh -function handle_kill() { - clear_output - cleanup +function shunpo_handle_kill() { + shunpo_clear_output + shunpo_cleanup exit 1 } -trap 'handle_kill' SIGINT +trap 'shunpo_handle_kill' SIGINT -if ! assert_bookmarks_exist; then +if ! shunpo_assert_bookmarks_exist; then exit 1 fi -interact_bookmarks "List Bookmarks" -cleanup +shunpo_interact_bookmarks "List Bookmarks" +shunpo_cleanup diff --git a/src/remove_bookmark.sh b/src/remove_bookmark.sh index b140c90..2381fb9 100755 --- a/src/remove_bookmark.sh +++ b/src/remove_bookmark.sh @@ -1,56 +1,56 @@ #!/bin/bash # Colors and formatting. -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$SCRIPT_DIR/colors.sh" -source "$SCRIPT_DIR/functions.sh" +SHUNPO_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SHUNPO_SCRIPT_DIR/colors.sh" +source "$SHUNPO_SCRIPT_DIR/functions.sh" -function handle_kill() { - clear_output - cleanup +function shunpo_handle_kill() { + shunpo_clear_output + shunpo_cleanup exit 1 } -trap 'handle_kill' SIGINT +trap 'shunpo_handle_kill' SIGINT # Check if bookmarks exist. -if ! assert_bookmarks_exist; then +if ! shunpo_assert_bookmarks_exist; then exit 1 fi -interact_bookmarks "Remove Bookmarks" $1 +shunpo_interact_bookmarks "Remove Bookmarks" $1 # Handle case where bookmark is not set. Corresponds to return code 2. if [ $? -eq 2 ]; then - if declare -f cleanup >/dev/null; then - cleanup + if declare -f shunpo_cleanup >/dev/null; then + shunpo_cleanup fi - echo -e "${BOLD}${ORANGE}Bookmark is Empty.${RESET}" + echo -e "${SHUNPO_BOLD}${SHUNPO_ORANGE}Bookmark is Empty.${SHUNPO_RESET}" exit 1 fi bookmarks=() while IFS= read -r bookmark; do bookmarks+=("$bookmark") -done <"$BOOKMARKS_FILE" +done <"$SHUNPO_BOOKMARKS_FILE" -if [[ -z $selected_dir ]]; then - unset selected_dir +if [[ -z $shunpo_selected_dir ]]; then + unset shunpo_selected_dir exit 1 -elif [[ $selected_bookmark_index -ge 0 ]] && [[ $selected_bookmark_index -lt ${#bookmarks[@]} ]]; then +elif [[ $shunpo_selected_bookmark_index -ge 0 ]] && [[ $shunpo_selected_bookmark_index -lt ${#bookmarks[@]} ]]; then # Remove the selected bookmark from the file. - awk -v dir="$selected_dir" '$0 != dir' "$BOOKMARKS_FILE" >"${BOOKMARKS_FILE}.tmp" && mv "${BOOKMARKS_FILE}.tmp" "$BOOKMARKS_FILE" + awk -v dir="$shunpo_selected_dir" '$0 != dir' "$SHUNPO_BOOKMARKS_FILE" >"${SHUNPO_BOOKMARKS_FILE}.tmp" && mv "${SHUNPO_BOOKMARKS_FILE}.tmp" "$SHUNPO_BOOKMARKS_FILE" # Display the removed bookmark message. - echo -e "${RED}${BOLD}Removed bookmark:${RESET} $selected_dir" + echo -e "${SHUNPO_RED}${SHUNPO_BOLD}Removed bookmark:${SHUNPO_RESET} $shunpo_selected_dir" # Delete the bookmarks file if it is empty. - if [ ! -s "$BOOKMARKS_FILE" ]; then - rm -f "$BOOKMARKS_FILE" + if [ ! -s "$SHUNPO_BOOKMARKS_FILE" ]; then + rm -f "$SHUNPO_BOOKMARKS_FILE" fi else exit 1 fi -cleanup +shunpo_cleanup