nav


Logs | Files | LICENSE | GitLab


1
commit 0c515fe33897e932586508143e254035147e8389
2
Author: Connor Etherington <[email protected]>
3
Date:   Wed Sep 7 03:12:17 2022 +0200
4
5
    Auto-Commit Update - 20220907
6
---
7
 usr/bin/nav | 88 +++++++++++++++++++++++++++++++++++++++++++++----------------
8
 1 file changed, 66 insertions(+), 22 deletions(-)
9
10
diff --git a/usr/bin/nav b/usr/bin/nav
11
index a638d00..1a1ada4 100755
12
--- a/usr/bin/nav
13
+++ b/usr/bin/nav
14
@@ -8,6 +8,8 @@ PROD_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nav"
15
 
16
 CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/nav/config"
17
 
18
+MENU_DIRS_FILE="${PROD_DIR}/menuDirs"
19
+  
20
 
21
 GETPATH(){
22
   SELECT_PATH=$(dialog \
23
@@ -26,42 +28,84 @@ GETCMD(){
24
     10 70 3>&1 1>&2 2>&3 3>&1) || exit 1
25
 }
26
 
27
+ACTION(){
28
+  dialog \
29
+    --title "${TITLE}" \
30
+    --yes-label "Add to Nav Menu" \
31
+    --no-label "Create Nav Alias" \
32
+    --yesno "\\nWould you like to add this directory to the Nav Menu or create a new shortcut command/alias?" \
33
+    12 70 3>&1 1>&2 2>&3 3>&1 ; ACT=$?
34
+}
35
+
36
 ISCORRECT(){
37
-  CORRECT=$(dialog \
38
+  dialog \
39
     --title "${TITLE}" \
40
     --yesno "\\nIs this correct?\\n\\nTrigger: ${CMD}\\n\\nDirectory: ${1}\\n" \
41
-    12 70 3>&1 1>&2 2>&3 3>&1) || $0
42
+    12 70 3>&1 1>&2 2>&3 3>&1 || $0
43
 }
44
 
45
+ISCORRECTMENU(){
46
+  dialog \
47
+    --title "${TITLE}" \
48
+    --yesno "\\nIs this correct?\\n\\nDirectory: ${1}\\n\\n\\nThis Directory will be added to the Nav Menu.\\n\\nThe Menu can be open with 'nav -m', or 'nav --menu'.\\n" \
49
+    14 70 3>&1 1>&2 2>&3 3>&1  || $0
50
+}
51
 
52
+INIT_CHECK(){
53
+  [[ ${NAV_INIT} != "initialized" ]] && dialog \
54
+    --title "${TITLE}" \
55
+    --msgbox "\\n                         Welcome to Nav!\\n\\n\\nNav will create a configuration file in ${PROD_DIR}\\n\\n\\nPlease enter this line into your bash/zshrc file to enable Nav:\\n\\nsource ${CONFIG}\\n" \
56
+    16 70 && trap "echo 'source ${CONFIG}   # --> (put in your bash/zshrc file)'" EXIT
57
 
58
-! [ -d  ${PROD_DIR} ] && mkdir -p ${PROD_DIR}
59
+  return 0
60
 
61
-! [ -f  ${CONFIG} ] && echo 'export NAV_INIT="initialized"' > ${CONFIG}
62
+}
63
 
64
+MAIN(){
65
 
66
-[[ ${NAV_INIT} != "initialized" ]] && dialog \
67
-  --title "${TITLE}" \
68
-  --msgbox "\\n                         Welcome to Nav!\\n\\n\\nNav will create a configuration file in ${PROD_DIR}\\n\\n\\nPlease enter this line into your bash/zshrc file to enable Nav:\\n\\nsource ${CONFIG}\\n" \
69
-  16 70 && trap "echo 'source ${CONFIG}   # --> (put in your bash/zshrc file)'" EXIT
70
+  while [[ ${SELECTION} == "" ]] ; do
71
 
72
-while [[ $CMD == "" ]] ; do
73
-  GETCMD
74
-done
75
+    GETPATH "${TEXT}" && case ${SELECT_PATH} in
76
+      "UP") cd .. ;;
77
+      "SELECT") SELECTION=${PWD} ;;
78
+      *) ! cd ${SELECT_PATH} && dialog --title "${TITLE}" --msgbox "\\n       Directory not found.\\n" 10 70 ;;
79
+    esac
80
+  
81
+  done
82
 
83
-while [[ ${SELECTION} == "" ]] ; do
84
+  while [[ -z ${ACT}  ]] ; do
85
+    ACTION
86
+  done
87
 
88
-  GETPATH "${TEXT}" && case ${SELECT_PATH} in
89
-    "UP") cd .. ;;
90
-    "SELECT") SELECTION=${PWD} ;;
91
-    *) ! cd ${SELECT_PATH} && dialog --title "${TITLE}" --msgbox "\\n       Directory not found.\\n" 10 70 ;;
92
-  esac
93
-done
94
+  [[ ${ACT} == 1 ]] && while [[ -z ${CMD} ]] ; do
95
+    GETCMD && ISCORRECT "${SELECTION}" &&
96
+      ISCORRECT ${SELECTION} && cat ${CONFIG}|grep -q "^${CMD}=" && 
97
+      sed -i "s|alias ${CMD}=.*|alias ${CMD}='cd `realpath ${SELECTION}` ; ls -1a'|" ${CONFIG} ||
98
+      echo "alias ${CMD}='cd `realpath ${SELECTION}` ; ls -1a'" >> ${CONFIG}
99
+    done
100
 
101
+  [[ ${ACT} == 0 ]] && ISCORRECTMENU "${SELECTION}" && 
102
+    echo `realpath ${SELECTION}` >> ${MENU_DIRS_FILE}
103
+
104
+  ${SHELL}
105
+}  
106
+
107
+MENU(){
108
+  goTo=$(cat ${MENU_DIRS_FILE} | uniq | fzf --preview 'ls -1a {}')
109
+  cd ${goTo} && ls -1a
110
+}
111
+
112
+
113
+ # Script starts:
114
+# ---
115
+
116
+! [ -d  ${PROD_DIR} ] && mkdir -p ${PROD_DIR}
117
+
118
+! [ -f  ${CONFIG} ] && echo 'export NAV_INIT="initialized"' > ${CONFIG}
119
 
120
-ISCORRECT ${SELECTION} && cat ${CONFIG}|grep -q "^${CMD}=" && 
121
-  sed -i "s|alias ${CMD}=.*|alias ${CMD}='cd `realpath ${SELECTION}` ; ls -1a'|" ${CONFIG} ||
122
-  echo "alias ${CMD}='cd `realpath ${SELECTION}` ; ls -1a'" >> ${CONFIG}
123
 
124
-${SHELL}
125
+INIT_CHECK && case $1 in
126
+  '-m'|'--menu'|'m'|'menu') MENU ;;
127
+  *) MAIN ;;
128
+esac
129