tenseleyflow/gump / 655b33b

Browse files

add g and g - support for home and previous directory

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
655b33bb038a2349bba30de7c1832899512254e9
Parents
84105d1
Tree
2232380

1 changed file

StatusFile+-
M src/cmd/init.rs 35 17
src/cmd/init.rsmodified
@@ -58,13 +58,19 @@ fi
5858
             r#"
5959
 # Jump function
6060
 {cmd}() {{
61
-    local result
62
-    result=$(command gump query -- "$@")
63
-    if [[ -n "$result" ]]; then
64
-        builtin cd -- "$result" && __gump_hook
61
+    if [[ $# -eq 0 ]]; then
62
+        builtin cd ~ && __gump_hook
63
+    elif [[ $# -eq 1 && "$1" == "-" ]]; then
64
+        builtin cd - && __gump_hook
6565
     else
66
-        echo "gump: no match found" >&2
67
-        return 1
66
+        local result
67
+        result=$(command gump query -- "$@")
68
+        if [[ -n "$result" ]]; then
69
+            builtin cd -- "$result" && __gump_hook
70
+        else
71
+            echo "gump: no match found" >&2
72
+            return 1
73
+        fi
6874
     fi
6975
 }}
7076
 
@@ -141,13 +147,19 @@ __gump_hook() {
141147
             r#"
142148
 # Jump function
143149
 {cmd}() {{
144
-    local result
145
-    result=$(command gump query -- "$@")
146
-    if [[ -n "$result" ]]; then
147
-        builtin cd -- "$result"
150
+    if [[ $# -eq 0 ]]; then
151
+        builtin cd ~
152
+    elif [[ $# -eq 1 && "$1" == "-" ]]; then
153
+        builtin cd -
148154
     else
149
-        echo "gump: no match found" >&2
150
-        return 1
155
+        local result
156
+        result=$(command gump query -- "$@")
157
+        if [[ -n "$result" ]]; then
158
+            builtin cd -- "$result"
159
+        else
160
+            echo "gump: no match found" >&2
161
+            return 1
162
+        fi
151163
     fi
152164
 }}
153165
 
@@ -242,12 +254,18 @@ end
242254
             r#"
243255
 # Jump function
244256
 function {cmd} --description "Jump to a directory"
245
-    set -l result (command gump query -- $argv)
246
-    if test -n "$result"
247
-        cd $result
257
+    if test (count $argv) -eq 0
258
+        cd ~
259
+    else if test (count $argv) -eq 1 -a "$argv[1]" = "-"
260
+        cd -
248261
     else
249
-        echo "gump: no match found" >&2
250
-        return 1
262
+        set -l result (command gump query -- $argv)
263
+        if test -n "$result"
264
+            cd $result
265
+        else
266
+            echo "gump: no match found" >&2
267
+            return 1
268
+        end
251269
     end
252270
 end
253271