From e137a999026a4ca1364144efe90b11990eae1dde Mon Sep 17 00:00:00 2001 From: Alan Hoyle Date: Thu, 17 May 2018 11:23:24 -0400 Subject: [PATCH 1/8] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d652cf..e77a052 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ HyperJump consists of 3 command line commands (functions). * __jr__ - Remember Jump. Bookmarks current directory. Run ``jr nickname`` to add current directory, or just run ``jr`` and use the interactive mode. * __jf__ - Forget Jump. Deletes the current directory from the bookmarks. Run ``jf`` while in a directory you want forgotten or ``jf nickname`` to forget a specific nickname. * __jj__ - Jump to a bookmark location. Run ``jj nickname`` to jump to a location or just ``jj`` to get a list of all bookmarks. You can also run ``jj nickname command`` to jump to a location and than run the command specified with "./" as the first argument. So, for instance, you can run ``jj myProject open subl`` on OSX to jump to the myProject directory and open the myProject directory in Finder and Sublime Text. +* __jp__ - Jump to a bookmark location and save that location to the directory stack. Usage is like ``jj`` but uses ``pushd`` instead of ``cd``. -All of the commands have autocomplete. Both __jj__ and __jf__ will autocomplete with nicknames of bookmarked locations. The __jr__ command will autocomplete with the basename of the current directory. After the first argument, __jj__ will autocomplete with list of available system commands (programs). +All of the commands have autocomplete. __jj__, __jp__, and __jf__ will autocomplete with nicknames of bookmarked locations. The __jr__ command will autocomplete with the basename of the current directory. After the first argument, __jj__ and __jp__ will autocomplete with list of available system commands (programs). **Examples:** @@ -26,10 +27,15 @@ $ jf AnotherDir # Jump to a Directory $ jj $ jj MyDir + +# Jump to a Directory and push to dirs +$ jp +$ jp MyDir # Jump to a directory and open the directory in another program(s) $ jj MyDir open $ jj MyDir open subl tm +$ jp MyDir open ``` ## How To Install From 751f882a94d001d1fa3066d27ce0b683b4280c59 Mon Sep 17 00:00:00 2001 From: Alan Hoyle Date: Thu, 17 May 2018 11:26:36 -0400 Subject: [PATCH 2/8] added jp --- hyperjump | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/hyperjump b/hyperjump index 4306e23..77936f8 100644 --- a/hyperjump +++ b/hyperjump @@ -19,7 +19,7 @@ function _hyperjumpdatabase() { echo "$db" } -# Jump Remamber - Adds a jump to the database +# Jump Remember - Adds a jump to the database function jr() { local db=$(_hyperjumpdatabase) local wd=$(pwd) @@ -167,6 +167,70 @@ function jj() { fi } +# Jump Push to Nickname - Shows the Dialog Menu with all of the jumps in the db +function jp() { + local db=$(_hyperjumpdatabase) + local foundDialog=0 + + # If no name on the prompt, than pop up the dialog, else use $1 + if [[ -z "$1" ]]; then + if ! type dialog > /dev/null 2>&1; then + # Dialog Utility NOT found, so show alternative + echo Dialog utility NOT found. Install Dialog to get a nice menu of jump locations. + echo List of Saved Locations: + while read line + do + printf " %-25s %s \n" "${line%:*}" "${line#*:}" + done < <(cat "$db") + else + local foundDialog=1 + local list="" + while read line + do + line="'${line%:*}' '${line#*:}' " + list+=$line + done < <(cat "$db") + + if [[ "$list" == "" ]]; then + echo The HyperJump Database is Empty. Bookmark a directory with the jr command to get started. + else + local cmd="dialog --menu 'Where do you want to jump to?' 22 76 16 $list" + local choice=$(eval "$cmd" 2>&1 >/dev/tty) + clear + fi + fi + else + local choice=$1 + fi + + # Check if the Jump is legit, and jump + if grep -q "^$choice:" "$db"; then + local line=$(grep "^$choice:" "$db" | head -n 1) + local target=${line#*:} + echo Navigating to "$choice" at "$target" and adding to dirs + pushd "$target" + # Run Additional Commands If Specified + local param + for param in ${@:2} + do + if [[ ! -z "$param" && "$param" != "" ]]; then + local cmd="$param ./" + echo Running \"$cmd\" inside $choice + eval "$cmd" + fi + done + else + if [[ -z "$choice" ]]; then + # Do not show the message if Dialog was not found + if [[ "$foundDialog" -eq 1 ]]; then + echo "Jump Cancelled" + fi + else + echo "Jump Nickname isn't in the Database" + fi + fi +} + # Autocomplete for Jump to Nickname _jj() { local db=$(_hyperjumpdatabase) @@ -198,5 +262,6 @@ if [[ -n "${ZSH_VERSION-}" ]]; then fi complete -F _jj jj +complete -F _jj jp complete -F _jj jf -complete -F _jr jr \ No newline at end of file +complete -F _jr jr From aae4425a06abbea24b0745fab7ddc6c00c5e149a Mon Sep 17 00:00:00 2001 From: Alan Hoyle Date: Tue, 18 Sep 2018 15:05:38 -0400 Subject: [PATCH 3/8] added hjsort to sort if manually edited, and 'jr'sorts each time a new jump is added. --- hyperjump | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hyperjump b/hyperjump index 77936f8..b1251e3 100644 --- a/hyperjump +++ b/hyperjump @@ -19,6 +19,21 @@ function _hyperjumpdatabase() { echo "$db" } +# Sort Hyperjump Database +function hjsort() { + local dbdir="$HOME"/.local/lib + local db="$dbdir"/hyperjumpdb + if [ -x "$(command -v sort)" ] ; then + if [[ -f $db ]] ; then + sort -o $db $db + else + echo "Can't sort hyperjump database: db does not exist" + fi + else + echo "Can't sort hyperjump database: sort command does not exist" + fi +} + # Jump Remember - Adds a jump to the database function jr() { local db=$(_hyperjumpdatabase) @@ -58,6 +73,9 @@ function jr() { else echo "$nick:$wd" >> "$db" echo "Added $wd with Nickname \"$nick\" to the database." + if [ -x "$(command -v sort)" ] ; then + sort -o $db $db + fi fi fi } From 0a9aa6604c5f2ed3799f22159b69a9288a2f9de8 Mon Sep 17 00:00:00 2001 From: Alan Hoyle Date: Tue, 18 Sep 2018 15:05:38 -0400 Subject: [PATCH 4/8] hyperjump: added 'hjsort' to sort if manually edited, and 'jr' sorts each time a new jump is added. README.md: added documentation about hjsort --- README.md | 16 ++++++++++------ hyperjump | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e77a052..e7a61f8 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,11 @@ __HyperJump__ - simple and quick bookmark tool for bash and zsh shells. I found ## How To Use HyperJump consists of 3 command line commands (functions). -* __jr__ - Remember Jump. Bookmarks current directory. Run ``jr nickname`` to add current directory, or just run ``jr`` and use the interactive mode. -* __jf__ - Forget Jump. Deletes the current directory from the bookmarks. Run ``jf`` while in a directory you want forgotten or ``jf nickname`` to forget a specific nickname. -* __jj__ - Jump to a bookmark location. Run ``jj nickname`` to jump to a location or just ``jj`` to get a list of all bookmarks. You can also run ``jj nickname command`` to jump to a location and than run the command specified with "./" as the first argument. So, for instance, you can run ``jj myProject open subl`` on OSX to jump to the myProject directory and open the myProject directory in Finder and Sublime Text. -* __jp__ - Jump to a bookmark location and save that location to the directory stack. Usage is like ``jj`` but uses ``pushd`` instead of ``cd``. +* __jr__ - Jump Remember. Bookmarks current directory. Run ``jr nickname`` to add current directory, or just run ``jr`` and use the interactive mode. +* __jf__ - Jump Forget. Deletes the current directory from the bookmarks. Run ``jf`` while in a directory you want forgotten or ``jf nickname`` to forget a specific nickname. +* __jj__ - Jump Jump. Jumps to a bookmark location. Run ``jj nickname`` to jump to a location or just ``jj`` to get a list of all bookmarks. You can also run ``jj nickname command`` to jump to a location and than run the command specified with "./" as the first argument. So, for instance, you can run ``jj myProject open subl`` on OSX to jump to the myProject directory and open the myProject directory in Finder and Sublime Text. +* __jp__ - Jump Push. Jumps to a bookmark location and saves that location to the directory stack. Usage is like ``jj`` but uses ``pushd`` instead of ``cd``. +* __hjsort__ - Sort the hyperjump list (Note that running a "jr" will also sort the list) All of the commands have autocomplete. __jj__, __jp__, and __jf__ will autocomplete with nicknames of bookmarked locations. The __jr__ command will autocomplete with the basename of the current directory. After the first argument, __jj__ and __jp__ will autocomplete with list of available system commands (programs). @@ -24,11 +25,11 @@ $ jf # Forget another directory $ jf AnotherDir -# Jump to a Directory +# Jump to a directory $ jj $ jj MyDir -# Jump to a Directory and push to dirs +# Jump to a directory and push to dirs $ jp $ jp MyDir @@ -36,6 +37,9 @@ $ jp MyDir $ jj MyDir open $ jj MyDir open subl tm $ jp MyDir open + +# Sort the list of bookmarks (not normally necessary as running jr sorts the list) +$ hjsort ``` ## How To Install diff --git a/hyperjump b/hyperjump index 77936f8..0a3b3fc 100644 --- a/hyperjump +++ b/hyperjump @@ -19,6 +19,21 @@ function _hyperjumpdatabase() { echo "$db" } +# Sort Hyperjump Database +function hjsort() { + local dbdir="$HOME"/.local/lib + local db="$dbdir"/hyperjumpdb + if [ -x "$(command -v sort)" ] ; then + if [[ -f $db ]] ; then + sort -t: -o $db $db + else + echo "Can't sort hyperjump database: db does not exist" + fi + else + echo "Can't sort hyperjump database: sort command does not exist" + fi +} + # Jump Remember - Adds a jump to the database function jr() { local db=$(_hyperjumpdatabase) @@ -58,6 +73,9 @@ function jr() { else echo "$nick:$wd" >> "$db" echo "Added $wd with Nickname \"$nick\" to the database." + if [ -x "$(command -v sort)" ] ; then + sort -t: -o $db $db + fi fi fi } From 9c2b7ac4637a0112e0288f476c3caf9f5bc96d2e Mon Sep 17 00:00:00 2001 From: Alan Hoyle Date: Tue, 18 Sep 2018 16:34:36 -0400 Subject: [PATCH 5/8] jp - jump push, hjsort - sort list, jr adds sort, updated README.md --- README.md | 16 ++++++---- hyperjump | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e77a052..e7a61f8 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,11 @@ __HyperJump__ - simple and quick bookmark tool for bash and zsh shells. I found ## How To Use HyperJump consists of 3 command line commands (functions). -* __jr__ - Remember Jump. Bookmarks current directory. Run ``jr nickname`` to add current directory, or just run ``jr`` and use the interactive mode. -* __jf__ - Forget Jump. Deletes the current directory from the bookmarks. Run ``jf`` while in a directory you want forgotten or ``jf nickname`` to forget a specific nickname. -* __jj__ - Jump to a bookmark location. Run ``jj nickname`` to jump to a location or just ``jj`` to get a list of all bookmarks. You can also run ``jj nickname command`` to jump to a location and than run the command specified with "./" as the first argument. So, for instance, you can run ``jj myProject open subl`` on OSX to jump to the myProject directory and open the myProject directory in Finder and Sublime Text. -* __jp__ - Jump to a bookmark location and save that location to the directory stack. Usage is like ``jj`` but uses ``pushd`` instead of ``cd``. +* __jr__ - Jump Remember. Bookmarks current directory. Run ``jr nickname`` to add current directory, or just run ``jr`` and use the interactive mode. +* __jf__ - Jump Forget. Deletes the current directory from the bookmarks. Run ``jf`` while in a directory you want forgotten or ``jf nickname`` to forget a specific nickname. +* __jj__ - Jump Jump. Jumps to a bookmark location. Run ``jj nickname`` to jump to a location or just ``jj`` to get a list of all bookmarks. You can also run ``jj nickname command`` to jump to a location and than run the command specified with "./" as the first argument. So, for instance, you can run ``jj myProject open subl`` on OSX to jump to the myProject directory and open the myProject directory in Finder and Sublime Text. +* __jp__ - Jump Push. Jumps to a bookmark location and saves that location to the directory stack. Usage is like ``jj`` but uses ``pushd`` instead of ``cd``. +* __hjsort__ - Sort the hyperjump list (Note that running a "jr" will also sort the list) All of the commands have autocomplete. __jj__, __jp__, and __jf__ will autocomplete with nicknames of bookmarked locations. The __jr__ command will autocomplete with the basename of the current directory. After the first argument, __jj__ and __jp__ will autocomplete with list of available system commands (programs). @@ -24,11 +25,11 @@ $ jf # Forget another directory $ jf AnotherDir -# Jump to a Directory +# Jump to a directory $ jj $ jj MyDir -# Jump to a Directory and push to dirs +# Jump to a directory and push to dirs $ jp $ jp MyDir @@ -36,6 +37,9 @@ $ jp MyDir $ jj MyDir open $ jj MyDir open subl tm $ jp MyDir open + +# Sort the list of bookmarks (not normally necessary as running jr sorts the list) +$ hjsort ``` ## How To Install diff --git a/hyperjump b/hyperjump index 4306e23..0a3b3fc 100644 --- a/hyperjump +++ b/hyperjump @@ -19,7 +19,22 @@ function _hyperjumpdatabase() { echo "$db" } -# Jump Remamber - Adds a jump to the database +# Sort Hyperjump Database +function hjsort() { + local dbdir="$HOME"/.local/lib + local db="$dbdir"/hyperjumpdb + if [ -x "$(command -v sort)" ] ; then + if [[ -f $db ]] ; then + sort -t: -o $db $db + else + echo "Can't sort hyperjump database: db does not exist" + fi + else + echo "Can't sort hyperjump database: sort command does not exist" + fi +} + +# Jump Remember - Adds a jump to the database function jr() { local db=$(_hyperjumpdatabase) local wd=$(pwd) @@ -58,6 +73,9 @@ function jr() { else echo "$nick:$wd" >> "$db" echo "Added $wd with Nickname \"$nick\" to the database." + if [ -x "$(command -v sort)" ] ; then + sort -t: -o $db $db + fi fi fi } @@ -167,6 +185,70 @@ function jj() { fi } +# Jump Push to Nickname - Shows the Dialog Menu with all of the jumps in the db +function jp() { + local db=$(_hyperjumpdatabase) + local foundDialog=0 + + # If no name on the prompt, than pop up the dialog, else use $1 + if [[ -z "$1" ]]; then + if ! type dialog > /dev/null 2>&1; then + # Dialog Utility NOT found, so show alternative + echo Dialog utility NOT found. Install Dialog to get a nice menu of jump locations. + echo List of Saved Locations: + while read line + do + printf " %-25s %s \n" "${line%:*}" "${line#*:}" + done < <(cat "$db") + else + local foundDialog=1 + local list="" + while read line + do + line="'${line%:*}' '${line#*:}' " + list+=$line + done < <(cat "$db") + + if [[ "$list" == "" ]]; then + echo The HyperJump Database is Empty. Bookmark a directory with the jr command to get started. + else + local cmd="dialog --menu 'Where do you want to jump to?' 22 76 16 $list" + local choice=$(eval "$cmd" 2>&1 >/dev/tty) + clear + fi + fi + else + local choice=$1 + fi + + # Check if the Jump is legit, and jump + if grep -q "^$choice:" "$db"; then + local line=$(grep "^$choice:" "$db" | head -n 1) + local target=${line#*:} + echo Navigating to "$choice" at "$target" and adding to dirs + pushd "$target" + # Run Additional Commands If Specified + local param + for param in ${@:2} + do + if [[ ! -z "$param" && "$param" != "" ]]; then + local cmd="$param ./" + echo Running \"$cmd\" inside $choice + eval "$cmd" + fi + done + else + if [[ -z "$choice" ]]; then + # Do not show the message if Dialog was not found + if [[ "$foundDialog" -eq 1 ]]; then + echo "Jump Cancelled" + fi + else + echo "Jump Nickname isn't in the Database" + fi + fi +} + # Autocomplete for Jump to Nickname _jj() { local db=$(_hyperjumpdatabase) @@ -198,5 +280,6 @@ if [[ -n "${ZSH_VERSION-}" ]]; then fi complete -F _jj jj +complete -F _jj jp complete -F _jj jf -complete -F _jr jr \ No newline at end of file +complete -F _jr jr From 512ec8c673862f1aba98993036fa0c57437bedee Mon Sep 17 00:00:00 2001 From: Alan Hoyle Date: Wed, 19 Sep 2018 15:14:27 -0400 Subject: [PATCH 6/8] jp dialog now says jump push, tabs to spaces --- hyperjump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperjump b/hyperjump index 0a3b3fc..b728ba1 100644 --- a/hyperjump +++ b/hyperjump @@ -212,7 +212,7 @@ function jp() { if [[ "$list" == "" ]]; then echo The HyperJump Database is Empty. Bookmark a directory with the jr command to get started. else - local cmd="dialog --menu 'Where do you want to jump to?' 22 76 16 $list" + local cmd="dialog --menu 'Where do you want to jump push to?' 22 76 16 $list" local choice=$(eval "$cmd" 2>&1 >/dev/tty) clear fi From 5f72c9816d657ee2e943d3852743e5204c2de89e Mon Sep 17 00:00:00 2001 From: Alan Hoyle Date: Wed, 19 Sep 2018 15:39:12 -0400 Subject: [PATCH 7/8] tabs to spaces, jr no longer allows nicknames containing colons. --- hyperjump | 473 +++++++++++++++++++++++++++--------------------------- 1 file changed, 239 insertions(+), 234 deletions(-) diff --git a/hyperjump b/hyperjump index b728ba1..2db3b7b 100644 --- a/hyperjump +++ b/hyperjump @@ -1,282 +1,287 @@ # Set Up the Database if it does not exist yet function _hyperjumpdatabase() { - local dbdir="$HOME"/.local/lib - local db="$dbdir"/hyperjumpdb - local db_old="$HOME"/.hyperjumpdb - if [[ ! -f "$db" ]]; then - # Create ~/.local/lib directory if it fors not exists - if [[ ! -d "$dbdir" ]]; then - mkdir -p "$dbdir" >> /dev/null - fi - # If old DB exists, move it to the new location - if [[ -f "$db_old" ]]; then - mv "$db_old" "$db" - else - touch "$db" - echo "home:$HOME" >> "$db" - fi - fi - echo "$db" + local dbdir="$HOME"/.local/lib + local db="$dbdir"/hyperjumpdb + local db_old="$HOME"/.hyperjumpdb + if [[ ! -f "$db" ]]; then + # Create ~/.local/lib directory if it fors not exists + if [[ ! -d "$dbdir" ]]; then + mkdir -p "$dbdir" >> /dev/null + fi + # If old DB exists, move it to the new location + if [[ -f "$db_old" ]]; then + mv "$db_old" "$db" + else + touch "$db" + echo "home:$HOME" >> "$db" + fi + fi + echo "$db" } # Sort Hyperjump Database function hjsort() { - local dbdir="$HOME"/.local/lib - local db="$dbdir"/hyperjumpdb - if [ -x "$(command -v sort)" ] ; then - if [[ -f $db ]] ; then - sort -t: -o $db $db - else - echo "Can't sort hyperjump database: db does not exist" - fi - else - echo "Can't sort hyperjump database: sort command does not exist" - fi + local dbdir="$HOME"/.local/lib + local db="$dbdir"/hyperjumpdb + if [ -x "$(command -v sort)" ] ; then + if [[ -f $db ]] ; then + sort -t: -o $db $db + else + echo "Can't sort hyperjump database: db does not exist" + fi + else + echo "Can't sort hyperjump database: sort command does not exist" + fi } # Jump Remember - Adds a jump to the database function jr() { - local db=$(_hyperjumpdatabase) - local wd=$(pwd) - local nick=${wd##*/} - local nick=${nick// /_} + local db=$(_hyperjumpdatabase) + local wd=$(pwd) + local nick=${wd##*/} + local nick=${nick// /_} - if grep -q "$wd$" "$db"; then - echo "This directory is already added to the database. Run 'jf' to forget it." - else - if [[ -z "$1" ]]; then - echo "We need a nickname for this directory. Use jr or specify it now." - read -p "[C]ancel, [U]se \"$nick\", Enter [N]ickname [C/U/N]: " -n 1 -e choice - case "$choice" in - "U" | "u" ) - echo "We are going to use $nick as the nickname for this directory." - ;; - "N" | "n" ) - local nick= - while [[ "$nick" = "" ]]; do - read -p "Enter a Nickname for this Directory and Press [Enter]: " -e nick - done - ;; - * ) - echo "Nothing was added to the database. Quitting." - return - ;; - esac - else - local nick=$1 - fi + if grep -q "$wd$" "$db"; then + echo "This directory is already added to the database. Run 'jf' to forget it." + else + if [[ -z "$1" ]]; then + echo "We need a nickname for this directory. Use jr or specify it now." + read -p "[C]ancel, [U]se \"$nick\", Enter [N]ickname [C/U/N]: " -n 1 -e choice + case "$choice" in + "U" | "u" ) + echo "We are going to use $nick as the nickname for this directory." + ;; + "N" | "n" ) + local nick= + while [[ "$nick" = "" ]]; do + read -p "Enter a Nickname for this Directory and Press [Enter]: " -e nick + done + ;; + * ) + echo "Nothing was added to the database. Quitting." + return + ;; + esac + else + local nick=$1 + fi - local nick=${nick// /_} + local nick=${nick// /_} - if grep -q "^$nick:" "$db"; then - echo "Oops, the nickname '$nick' is already in use :( Try again...." - else - echo "$nick:$wd" >> "$db" - echo "Added $wd with Nickname \"$nick\" to the database." - if [ -x "$(command -v sort)" ] ; then - sort -t: -o $db $db - fi - fi - fi + local colon=: + + if grep -q "^$nick:" "$db"; then + echo "Oops, the nickname '$nick' is already in use :( Try again...." + elif grep -q ":" <<<"$nick" ; then # [ -z "${nick##*$colon*}" ] ; then + echo "Oops, the nickname '$nick' contains a colon. Try again...." + + else + echo "$nick:$wd" >> "$db" + echo "Added $wd with Nickname \"$nick\" to the database." + if [ -x "$(command -v sort)" ] ; then + sort -t: -o $db $db + fi + fi + fi } # Jump Forget - Removes a jump location from the database function jf() { - local db=$(_hyperjumpdatabase) + local db=$(_hyperjumpdatabase) - if [[ -z "$1" ]]; then - local wd=$(pwd) - if grep -q ":$wd$" "$db"; then - local dbline=$(grep ":$wd$" "$db" | head -n 1) - local nickname=${dbline%:*} - else - echo "This directory is not in the database!" - return - fi - else - local nickname=$1 - if grep -q "^$nickname:" "$db"; then - local line=$(grep "^$nickname:" "$db" | head -n 1) - local wd=${line#*:} - else - echo "This nickname is not in the database!" - return - fi - fi + if [[ -z "$1" ]]; then + local wd=$(pwd) + if grep -q ":$wd$" "$db"; then + local dbline=$(grep ":$wd$" "$db" | head -n 1) + local nickname=${dbline%:*} + else + echo "This directory is not in the database!" + return + fi + else + local nickname=$1 + if grep -q "^$nickname:" "$db"; then + local line=$(grep "^$nickname:" "$db" | head -n 1) + local wd=${line#*:} + else + echo "This nickname is not in the database!" + return + fi + fi - echo "$nickname : $wd" - read -p "Forget It? [Y/N]: " -n 1 -e choice - case "$choice" in - "Y" | "y" ) - local tempfile=$(mktemp -t "XXXjumpdb") - grep -v ":$wd$" "$db" > "$tempfile" - cat "$tempfile" > "$db" - rm "$tempfile" - echo "$nickname is forgotten!" - ;; - * ) - echo "Nothing was deleted from the database. Quitting." - return - ;; - esac + echo "$nickname : $wd" + read -p "Forget It? [Y/N]: " -n 1 -e choice + case "$choice" in + "Y" | "y" ) + local tempfile=$(mktemp -t "XXXjumpdb") + grep -v ":$wd$" "$db" > "$tempfile" + cat "$tempfile" > "$db" + rm "$tempfile" + echo "$nickname is forgotten!" + ;; + * ) + echo "Nothing was deleted from the database. Quitting." + return + ;; + esac } # Jump to Nickname - Shows the Dialog Menu with all of the jumps in the db function jj() { - local db=$(_hyperjumpdatabase) - local foundDialog=0 + local db=$(_hyperjumpdatabase) + local foundDialog=0 - # If no name on the prompt, than pop up the dialog, else use $1 - if [[ -z "$1" ]]; then - if ! type dialog > /dev/null 2>&1; then - # Dialog Utility NOT found, so show alternative - echo Dialog utility NOT found. Install Dialog to get a nice menu of jump locations. - echo List of Saved Locations: - while read line - do - printf " %-25s %s \n" "${line%:*}" "${line#*:}" - done < <(cat "$db") - else - local foundDialog=1 - local list="" - while read line - do - line="'${line%:*}' '${line#*:}' " - list+=$line - done < <(cat "$db") + # If no name on the prompt, than pop up the dialog, else use $1 + if [[ -z "$1" ]]; then + if ! type dialog > /dev/null 2>&1; then + # Dialog Utility NOT found, so show alternative + echo Dialog utility NOT found. Install Dialog to get a nice menu of jump locations. + echo List of Saved Locations: + while read line + do + printf " %-25s %s \n" "${line%:*}" "${line#*:}" + done < <(cat "$db") + else + local foundDialog=1 + local list="" + while read line + do + line="'${line%:*}' '${line#*:}' " + list+=$line + done < <(cat "$db") - if [[ "$list" == "" ]]; then - echo The HyperJump Database is Empty. Bookmark a directory with the jr command to get started. - else - local cmd="dialog --menu 'Where do you want to jump to?' 22 76 16 $list" - local choice=$(eval "$cmd" 2>&1 >/dev/tty) - clear - fi - fi - else - local choice=$1 - fi + if [[ "$list" == "" ]]; then + echo The HyperJump Database is Empty. Bookmark a directory with the jr command to get started. + else + local cmd="dialog --menu 'Where do you want to jump to?' 22 76 16 $list" + local choice=$(eval "$cmd" 2>&1 >/dev/tty) + clear + fi + fi + else + local choice=$1 + fi - # Check if the Jump is legit, and jump - if grep -q "^$choice:" "$db"; then - local line=$(grep "^$choice:" "$db" | head -n 1) - local target=${line#*:} - echo Navigating to "$choice" at "$target" - cd "$target" - # Run Additional Commands If Specified - local param - for param in ${@:2} - do - if [[ ! -z "$param" && "$param" != "" ]]; then - local cmd="$param ./" - echo Running \"$cmd\" inside $choice - eval "$cmd" - fi - done - else - if [[ -z "$choice" ]]; then - # Do not show the message if Dialog was not found - if [[ "$foundDialog" -eq 1 ]]; then - echo "Jump Cancelled" - fi - else - echo "Jump Nickname isn't in the Database" - fi - fi + # Check if the Jump is legit, and jump + if grep -q "^$choice:" "$db"; then + local line=$(grep "^$choice:" "$db" | head -n 1) + local target=${line#*:} + echo Navigating to "$choice" at "$target" + cd "$target" + # Run Additional Commands If Specified + local param + for param in ${@:2} + do + if [[ ! -z "$param" && "$param" != "" ]]; then + local cmd="$param ./" + echo Running \"$cmd\" inside $choice + eval "$cmd" + fi + done + else + if [[ -z "$choice" ]]; then + # Do not show the message if Dialog was not found + if [[ "$foundDialog" -eq 1 ]]; then + echo "Jump Cancelled" + fi + else + echo "Jump Nickname isn't in the Database" + fi + fi } # Jump Push to Nickname - Shows the Dialog Menu with all of the jumps in the db function jp() { - local db=$(_hyperjumpdatabase) - local foundDialog=0 + local db=$(_hyperjumpdatabase) + local foundDialog=0 - # If no name on the prompt, than pop up the dialog, else use $1 - if [[ -z "$1" ]]; then - if ! type dialog > /dev/null 2>&1; then - # Dialog Utility NOT found, so show alternative - echo Dialog utility NOT found. Install Dialog to get a nice menu of jump locations. - echo List of Saved Locations: - while read line - do - printf " %-25s %s \n" "${line%:*}" "${line#*:}" - done < <(cat "$db") - else - local foundDialog=1 - local list="" - while read line - do - line="'${line%:*}' '${line#*:}' " - list+=$line - done < <(cat "$db") + # If no name on the prompt, than pop up the dialog, else use $1 + if [[ -z "$1" ]]; then + if ! type dialog > /dev/null 2>&1; then + # Dialog Utility NOT found, so show alternative + echo Dialog utility NOT found. Install Dialog to get a nice menu of jump locations. + echo List of Saved Locations: + while read line + do + printf " %-25s %s \n" "${line%:*}" "${line#*:}" + done < <(cat "$db") + else + local foundDialog=1 + local list="" + while read line + do + line="'${line%:*}' '${line#*:}' " + list+=$line + done < <(cat "$db") - if [[ "$list" == "" ]]; then - echo The HyperJump Database is Empty. Bookmark a directory with the jr command to get started. - else - local cmd="dialog --menu 'Where do you want to jump push to?' 22 76 16 $list" - local choice=$(eval "$cmd" 2>&1 >/dev/tty) - clear - fi - fi - else - local choice=$1 - fi + if [[ "$list" == "" ]]; then + echo The HyperJump Database is Empty. Bookmark a directory with the jr command to get started. + else + local cmd="dialog --menu 'Where do you want to jump push to?' 22 76 16 $list" + local choice=$(eval "$cmd" 2>&1 >/dev/tty) + clear + fi + fi + else + local choice=$1 + fi - # Check if the Jump is legit, and jump - if grep -q "^$choice:" "$db"; then - local line=$(grep "^$choice:" "$db" | head -n 1) - local target=${line#*:} - echo Navigating to "$choice" at "$target" and adding to dirs - pushd "$target" - # Run Additional Commands If Specified - local param - for param in ${@:2} - do - if [[ ! -z "$param" && "$param" != "" ]]; then - local cmd="$param ./" - echo Running \"$cmd\" inside $choice - eval "$cmd" - fi - done - else - if [[ -z "$choice" ]]; then - # Do not show the message if Dialog was not found - if [[ "$foundDialog" -eq 1 ]]; then - echo "Jump Cancelled" - fi - else - echo "Jump Nickname isn't in the Database" - fi - fi + # Check if the Jump is legit, and jump + if grep -q "^$choice:" "$db"; then + local line=$(grep "^$choice:" "$db" | head -n 1) + local target=${line#*:} + echo Navigating to "$choice" at "$target" and adding to dirs + pushd "$target" + # Run Additional Commands If Specified + local param + for param in ${@:2} + do + if [[ ! -z "$param" && "$param" != "" ]]; then + local cmd="$param ./" + echo Running \"$cmd\" inside $choice + eval "$cmd" + fi + done + else + if [[ -z "$choice" ]]; then + # Do not show the message if Dialog was not found + if [[ "$foundDialog" -eq 1 ]]; then + echo "Jump Cancelled" + fi + else + echo "Jump Nickname isn't in the Database" + fi + fi } # Autocomplete for Jump to Nickname _jj() { - local db=$(_hyperjumpdatabase) + local db=$(_hyperjumpdatabase) - local list="" - while read line - do - local list+=" ${line%:*}" - done < <(cat "$db") + local list="" + while read line + do + local list+=" ${line%:*}" + done < <(cat "$db") - local cur=${COMP_WORDS[COMP_CWORD]} - if [[ "$COMP_CWORD" -eq 1 ]]; then - COMPREPLY=( $(compgen -W "$list" -- "$cur") ) - else - COMPREPLY=( $(compgen -c "$cur") ) - fi + local cur=${COMP_WORDS[COMP_CWORD]} + if [[ "$COMP_CWORD" -eq 1 ]]; then + COMPREPLY=( $(compgen -W "$list" -- "$cur") ) + else + COMPREPLY=( $(compgen -c "$cur") ) + fi } _jr() { - local wd=$(pwd) - local nick=${wd##*/} - local nick=${nick// /_} - local cur=${COMP_WORDS[COMP_CWORD]} - COMPREPLY=( $(compgen -W "$nick" -- "$cur") ) + local wd=$(pwd) + local nick=${wd##*/} + local nick=${nick// /_} + local cur=${COMP_WORDS[COMP_CWORD]} + COMPREPLY=( $(compgen -W "$nick" -- "$cur") ) } if [[ -n "${ZSH_VERSION-}" ]]; then - autoload -U +X bashcompinit && bashcompinit + autoload -U +X bashcompinit && bashcompinit fi complete -F _jj jj From 2f4f5a1666b88ac653dc906a6ca73eb90fa38caa Mon Sep 17 00:00:00 2001 From: Alan Hoyle Date: Wed, 5 Dec 2018 16:34:04 -0500 Subject: [PATCH 8/8] Fixed bug if a colon was included in a nickname; jr output the existing nickname if it already exists --- hyperjump | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hyperjump b/hyperjump index 2db3b7b..1d6855d 100644 --- a/hyperjump +++ b/hyperjump @@ -41,8 +41,12 @@ function jr() { local nick=${wd##*/} local nick=${nick// /_} - if grep -q "$wd$" "$db"; then - echo "This directory is already added to the database. Run 'jf' to forget it." + if grep -q ":$wd$" "$db"; then + + local dbline=$(grep ":$wd$" "$db" | head -n 1) + local nickname=${dbline%:*} + + echo "This directory is already added as '$nickname': run 'jf' to forget it." else if [[ -z "$1" ]]; then echo "We need a nickname for this directory. Use jr or specify it now."