| Hash | Commit message | Author | Date | Files | + | - |
1 | commit 9b374bd8f99a94996fe160b9c7a9dcab1d10a1e1 |
2 | Author: Connor Etherington <[email protected]> |
3 | Date: Mon Aug 1 09:34:59 2022 +0200 |
4 | |
5 | Auto-Commit Update 01.08.2022 - 09:34:59 |
6 | --- |
7 | usr/bin/snip | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
8 | 1 file changed, 118 insertions(+) |
9 | |
10 | diff --git a/usr/bin/snip b/usr/bin/snip |
11 | new file mode 100755 |
12 | index 0000000..f92bfaf |
13 | --- /dev/null |
14 | +++ b/usr/bin/snip |
15 | @@ -0,0 +1,118 @@ |
16 | +#!/usr/bin/env bash |
17 | +####################################################################################################################################################################################### |
18 | +# ~ S N I P ~ # |
19 | +####################################################################################################################################################################################### |
20 | + |
21 | +# Globals: |
22 | + |
23 | +TITLE=' ~ Snip Snippet Editor ~' |
24 | +SNIPDATA="${XDG_DATA_HOME:-$HOME/.local/share}/snip" |
25 | + |
26 | + |
27 | +# Tempfiles and Cleanup: |
28 | + |
29 | +tmpSnipName=$(mktemp) |
30 | +tmpSnipType=$(mktemp) |
31 | + |
32 | +trap "rm -f ${tmpSnipName} ${tmpSnipType}" EXIT INT TERM |
33 | + |
34 | + |
35 | +## Funtions: |
36 | + |
37 | +newCatagory(){ \ |
38 | + snipType=$(dialog \ |
39 | + --stdout --colors \ |
40 | + --title " ~ New Snippet ~ " \ |
41 | + --inputbox "\\n Please Enter Snippet Extension Type :\\n " 11 60 ) |
42 | + |
43 | + [ -z "${snipType}" ] && err "No Snippet Type Was Entered..." |
44 | + |
45 | + ${EDITOR} ${SNIPDIR}/${snipType}.snippets &&[41m |
46 | + notify-send " ✅ New Snippet File Created!" && |
47 | + exit 0 || err "Snippet file could not be altered ..."[41m |
48 | +} |
49 | + |
50 | +firstRun(){[41m |
51 | + for pkg in dialog dunst neovim ; do[41m |
52 | + ! sudo pacman -Qq ${pkg} &&[41m |
53 | + ! sudo pacman -S ${pkg} --noconfirm && return 1 |
54 | + done |
55 | + |
56 | +SNIPDIR=$(dialog \ |
57 | + --stdout \ |
58 | + --title "$TITLE " \ |
59 | + --inputbox "\\n Please enter your local vim snippets directory (if you have one) :\\n\\n\\nNOTE: This will only be asked once, after which, can be changed by editing the config file located at '${SNIPDATA}/sniprc'\\n\\nLeave blank for default ( ~/.config/nvim/snippets ).\\n " 18 97 |
60 | +) || err "User Exited." |
61 | + |
62 | +[[ -n "${SNIPDIR}" ]] || SNIPDIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvim/snippets" |
63 | + |
64 | +SNIPDIR="$(realpath ${SNIPDIR})" |
65 | + |
66 | +! [ -e ${SNIPDIR} ] && mkdir -p ${SNIPDIR}[41m |
67 | +! [ -e ${SNIPDATA} ] && mkdir -p ${SNIPDATA} |
68 | + |
69 | +! [[ -e ${SNIPDATA}/sniprc ]] &&[41m |
70 | + echo -e "# ~ Snip Config File ~ #\n\nSNIPDIR=\"${SNIPDIR}\"" \ |
71 | + >> ${SNIPDATA}/sniprc && return 0 |
72 | + |
73 | +! cat ${SNIPDATA}/sniprc | grep -q "SNIPDIR" && |
74 | + echo "SNIPDIR=\"${SNIPDIR}\"" >> ${SNIPDATA}/sniprc || |
75 | + sed -i "s/SNIPDIR=.*/SNIPDIR=\"${SNIPDIR}\"/" ${SNIPDATA}/sniprc |
76 | +} |
77 | + |
78 | +editSnippet(){ dialog \ |
79 | + --stdout --no-tags --colors \ |
80 | + --title " ~ Select Snippet Type ~ " \ |
81 | + --menu "\\n Please Select Snippet Type :\\n " 16 50 70 \ |
82 | + 'ALL' 'All Snippets' "${snipType[@]}" 'NEW' 'Define New Snippet Type' \ |
83 | + >${tmpSnipType} || exit 0 |
84 | +[41m |
85 | +[[ -z $(cat ${tmpSnipType}) ]] && err "No Snippet Type Was Entered..." |
86 | +[[ $(cat ${tmpSnipType}) == 'NEW' ]] && newCatagory |
87 | +[[ $(cat ${tmpSnipType}) == 'ALL' ]] && ${EDITOR} ${SNIPDIR}/_.snippets &&[41m |
88 | + notify-send "✅ Snippet File Altered!" &&return 0 |
89 | + |
90 | + ${EDITOR} ${SNIPDIR}/$(cat ${tmpSnipType}) && |
91 | + notify-send "✅ Snippet File Altered!" && |
92 | + ! exit 0 && err "Snippet file could not be created..." |
93 | +} |
94 | + |
95 | +checkNet(){ \ |
96 | + ! curl -s --connect-timeout 8 https://example.com/ > /dev/null 2>&1 && |
97 | + echo -e "\n\033[31mA working internet connection is required to obtain the required dependencies.\n\033[0m" && |
98 | + exit 1 |
99 | +} |
100 | + |
101 | +err(){ \ |
102 | + notify-send -u critical -t 2000 "ERROR: ${*}" && clear &&[41m |
103 | + echo -e "\n$(tput bold ; tput setaf 1)[-] ERROR: ${*}$(tput sgr0)" ; exit 1 |
104 | +} |
105 | + |
106 | + |
107 | + |
108 | + # -----------------# |
109 | + # # Script Begins: # # |
110 | + #------------------# |
111 | + |
112 | + |
113 | +## Prerequisites: |
114 | + |
115 | +! cat ${XDG_DATA_HOME:-$HOME/.local}/snip/sniprc|grep -q SNIPDIR >/dev/null 2>&1 && ! firstRun && checkNet |
116 | + |
117 | +source ${SNIPDATA}/sniprc >/dev/null 2>&1 |
118 | + |
119 | + |
120 | +echo 'snipType=(' >${tmpSnipName} |
121 | + |
122 | +for x in $(ls -1 ${SNIPDIR}); do |
123 | +echo "'${x}' '$(basename ${x} .snippets) \ |
124 | +Snippets'" >>${tmpSnipName} ; done |
125 | + |
126 | +sed -i "/_.snippets/d" ${tmpSnipName} |
127 | +echo ')' >>${tmpSnipName}[41m |
128 | + |
129 | +source ${tmpSnipName}[41m |
130 | +rm -f ${tmpSnipName} |
131 | + |
132 | +editSnippet |
133 | + |