nav


Logs | Files | LICENSE | GitLab


1
commit e774e8f08ccbdc36892d18952d44a72cc4632b0a
2
Author: Connor Etherington <[email protected]>
3
Date:   Thu Aug 18 18:12:41 2022 +0200
4
5
    Auto-Commit Update 18.08.2022 - 18:12:41
6
---
7
 usr/bin/nav                    | 70 ++++++++++++++++++++++++++++++++++++++++++
8
 usr/share/doc/nav/.gitkeep     |  0
9
 usr/share/licenses/nav/LICENSE |  2 +-
10
 3 files changed, 71 insertions(+), 1 deletion(-)
11
12
diff --git a/usr/bin/nav b/usr/bin/nav
13
new file mode 100755
14
index 0000000..cfdfbb3
15
--- /dev/null
16
+++ b/usr/bin/nav
17
@@ -0,0 +1,70 @@
18
+#!/usr/bin/env bash
19
+
20
+TITLE=' ~ Nav CLI ~ '
21
+
22
+TEXT="\\n       Please enter select mode to choose a directory.\\n"
23
+
24
+SELECT_MODE="\\n       Please select the directory for aliasing:\\n"
25
+
26
+PROD_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nav"
27
+
28
+CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/nav/config"
29
+
30
+
31
+GETPATH(){
32
+  SELECT_PATH=$(dialog \
33
+    --title "${TITLE}" --no-tags --stdout \
34
+    --menu "${1}" \
35
+    35 65 35 "UP" "* GO UP A DIRECTORY" "SELECT" "* SELECT MODE" \
36
+    $(for x in `find . -maxdepth 1 -type d|cut -d\  -f1|sed 's/^\.$//;s/^\.\.//;s/^\.\///'` ;
37
+    do echo "${x} ${x}" ; done ; unset x)) || exit 1
38
+}
39
+
40
+
41
+GETCMD(){
42
+  CMD=$(dialog \
43
+    --title "${TITLE}" \
44
+    --inputbox "Please enter the command to trigger the directory change:" \
45
+    10 70 3>&1 1>&2 2>&3 3>&1) || exit 1
46
+}
47
+
48
+ISCORRECT(){
49
+  CORRECT=$(dialog \
50
+    --title "${TITLE}" \
51
+    --yesno "\\nIs this correct?\\n\\nTrigger: ${CMD}\\n\\nDirectory: `realpath ${SELECT_PATH}`\\n" \
52
+    12 70 3>&1 1>&2 2>&3 3>&1) || $0
53
+}
54
+
55
+
56
+
57
+! [ -d  ${PROD_DIR} ] && mkdir -p ${PROD_DIR}
58
+
59
+! [ -f  ${CONFIG} ] && echo 'alias NAV_INIT="initialized"' > ${CONFIG}
60
+
61
+
62
+[[ $NAV_INIT != "initialized" ]] && dialog \
63
+  --title "${TITLE}" \
64
+  --msgbox "\\n                         Welcome to Nav!\\n\\n\\nNav will create a configuration file in ${PROD_DIR}\\n\\n\\nPlease enter the line into your bash/zshrc file to enable Nav:\\n\\nsource ${CONFIG}\\n" \
65
+  16 70 && trap "echo 'source ${CONFIG}   # --> (put in your bash/zshrc file)'" EXIT
66
+
67
+while [[ $CMD == "" ]] ; do
68
+  GETCMD
69
+done
70
+
71
+while [[ ${SELECTION} == "" ]] ; do
72
+
73
+  GETPATH "${TEXT}" && case ${SELECT_PATH} in
74
+    "UP") cd .. ;;
75
+    "SELECT") unset SELECTION && GETPATH "${SELECT_MODE}" && SELECTION=${SELECT_PATH} ;;
76
+    *) ! cd ${SELECT_PATH} && dialog --title "${TITLE}" --msgbox "\\n       Directory not found.\\n" 10 70 ;;
77
+  esac
78
+done
79
+
80
+
81
+ISCORRECT && cat ${CONFIG}|grep -q "${CMD}=" && 
82
+  sed -i "s|alias ${CMD}=.*|alias ${CMD}='cd `realpath ${SELECTION}` ; ls -a'|" ${CONFIG} ||
83
+  echo "alias ${CMD}='cd `realpath ${SELECTION}` ; ls -a'" >> ${CONFIG}
84
+
85
+
86
+
87
+
88
diff --git a/usr/share/doc/nav/.gitkeep b/usr/share/doc/nav/.gitkeep
89
deleted file mode 100644
90
index e69de29..0000000
91
diff --git a/usr/share/licenses/nav/LICENSE b/usr/share/licenses/nav/LICENSE
92
index 276f429..10210d7 100644
93
--- a/usr/share/licenses/nav/LICENSE
94
+++ b/usr/share/licenses/nav/LICENSE
95
@@ -1,7 +1,7 @@
96
 MIT/X Consortium License
97
 
98
 Creator /Maintainer :
99
-© 2020-2022 Connor Etherington <[email protected]>
100
+© 2020-present Connor Etherington <[email protected]>
101
 ---------------------------------------------------------------------------
102
 Contributors:
103