snip


Logs | Files | README | LICENSE | GitLab


1
commit 2d9e6785e34b0022e0e9be2c3ebc2063c806839e
2
Author: Connor Etherington <[email protected]>
3
Date:   Mon May 1 10:50:29 2023 +0200
4
5
    Auto-Commit Update - 20230501
6
---
7
 usr/bin/snip | 51 ++++++++++++++++++++++++++++++++-------------------
8
 1 file changed, 32 insertions(+), 19 deletions(-)
9
10
diff --git a/usr/bin/snip b/usr/bin/snip
11
index 1623275..f0bb8cf 100755
12
--- a/usr/bin/snip
13
+++ b/usr/bin/snip
14
@@ -8,6 +8,8 @@
15
 TITLE=' ~ Snip Snippet Editor ~'
16
 SNIPDATA="${XDG_DATA_HOME:-$HOME/.local/share}/snip"
17
 
18
+err(){ echo -e "\n\n[-] ERROR: ${*}" && exit 1 ; }
19
+
20
 
21
 # Tempfiles and Cleanup:
22
 
23
@@ -23,18 +25,32 @@ newCatagory(){ \
24
   snipType=$(dialog \
25
     --stdout --colors \
26
     --title " ~ New Snippet ~ " \
27
-    --inputbox "\\n         Please Enter Snippet Extension Type :\\n " 11 60 )
28
+    --inputbox "\\n            Please Enter Snippet Extension:\\n " 11 60 )
29
 
30
   [ -z "${snipType}" ] && err "No Snippet Type Was Entered..."
31
 
32
-  ${EDITOR} ${SNIPDIR}/${snipType}.snippets && 
33
+  snipFile=$(dialog \
34
+    --stdout --colors --no-tags \
35
+    --title " ~ New Snippet ~ " \
36
+    --menu "\\n Please Select Snippet Priority (10=highest):\\n "  16 50 70 \
37
+    "10" "10" \
38
+    "20" "20" \
39
+    "30" "30" \
40
+    "40" "40" \
41
+    "50" "50" \
42
+    "60" "60" || exit 0)
43
+
44
+  [ -z "${snipFile}" ] && err "No Snippet Type Was Entered..."
45
+
46
+  [ -d ${SNIPDIR}/${snipType} ] || mkdir -p ${SNIPDIR}/${snipType} >/dev/null 2>&1
47
+  ${EDITOR} ${SNIPDIR}/${snipType}/${snipType}p${snipFile%0}.snippets &&
48
   notify-send " ✅ New Snippet File Created!" &&
49
-  exit 0 || err "Snippet file could not be altered ..." 
50
+  exit 0 || err "Snippet file could not be altered ..."
51
 }
52
 
53
-firstRun(){ 
54
- for pkg in dialog dunst neovim ; do  
55
-   ! sudo pacman -Qq ${pkg} && 
56
+firstRun(){
57
+ for pkg in dialog dunst neovim ; do
58
+   ! sudo pacman -Qq ${pkg} &&
59
    ! sudo pacman -S ${pkg} --noconfirm && return 1
60
  done
61
 
62
@@ -45,13 +61,14 @@ SNIPDIR=$(dialog \
63
 ) || err "User Exited."
64
 
65
 [[ -n "${SNIPDIR}" ]] || SNIPDIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvim/snippets"
66
+[ -d ${SNIPDIR} ] || mkdir -p ${SNIPDIR} || err "Please check you have sufficient premissions to create directory at $SNIPDIR "
67
 
68
 SNIPDIR="$(realpath ${SNIPDIR})"
69
 
70
-! [ -e ${SNIPDIR} ] && mkdir -p ${SNIPDIR} 
71
+! [ -e ${SNIPDIR} ] && mkdir -p ${SNIPDIR}
72
 ! [ -e ${SNIPDATA} ] && mkdir -p ${SNIPDATA}
73
 
74
-! [[ -e ${SNIPDATA}/sniprc ]] && 
75
+! [[ -e ${SNIPDATA}/sniprc ]] &&
76
   echo -e "#            ~ Snip Config File ~            #\n\nSNIPDIR=\"${SNIPDIR}\"" \
77
   >> ${SNIPDATA}/sniprc && return 0
78
 
79
@@ -66,13 +83,13 @@ editSnippet(){ dialog \
80
   --menu "\\n         Please Select Snippet Type :\\n " 16 50 70 \
81
     "${snipType[@]}" 'NEW' 'Define New Snippet Type' \
82
     >${tmpSnipType} || exit 0
83
-  
84
+
85
 [[ -z $(cat ${tmpSnipType}) ]] && err "No Snippet Type Was Entered..."
86
 [[ $(cat ${tmpSnipType}) == 'NEW' ]] && newCatagory
87
-[[ $(cat ${tmpSnipType}) == 'ALL' ]] && ${EDITOR} ${SNIPDIR}/_.snippets && 
88
+[[ $(cat ${tmpSnipType}) == 'ALL' ]] && ${EDITOR} ${SNIPDIR}/_.snippets &&
89
   notify-send "✅  Snippet File Altered!" &&return 0
90
 
91
-  ${EDITOR} ${SNIPDIR}/$(cat ${tmpSnipType}) &&
92
+  ${EDITOR} $(find ${SNIPDIR} -name $(cat ${tmpSnipType})|sort) &&
93
   notify-send "✅  Snippet File Altered!" &&
94
   ! exit 0 && err "Snippet file could not be created..."
95
 }
96
@@ -83,11 +100,6 @@ checkNet(){ \
97
   exit 1
98
 }
99
 
100
-err(){ \
101
-  notify-send -u critical -t 2000 "ERROR: ${*}" && clear && 
102
-  echo -e "\n$(tput bold ; tput setaf 1)[-] ERROR: ${*}$(tput sgr0)" ; exit 1
103
-}
104
-
105
 
106
 
107
                                          # -----------------#
108
@@ -104,14 +116,15 @@ source ${SNIPDATA}/sniprc >/dev/null 2>&1
109
 
110
 echo 'snipType=(' >${tmpSnipName}
111
 
112
-for x in $(ls -1 ${SNIPDIR}|grep ".*\.snippets$"); do
113
+for Dirs in $(find ${SNIPDIR} -maxdepth 1 -type d|sort); do for x in $(ls -1 ${Dirs}|sort|grep ".*\.snippets$"); do
114
 echo "'${x}' '$(basename ${x} .snippets) \
115
 Snippets'" >>${tmpSnipName} ; done
116
+done
117
 
118
 sed -i "/_.snippets/d" ${tmpSnipName}
119
-echo ')' >>${tmpSnipName} 
120
+echo ')' >>${tmpSnipName}
121
 
122
-source ${tmpSnipName} 
123
+source ${tmpSnipName}
124
 rm -f ${tmpSnipName}
125
 
126
 editSnippet