| Hash | Commit message | Author | Date | Files | + | - |
1 | commit baf20fa39d8f330e59cc4c8b42d2e45809c49497 |
2 | Author: Connor Etherington <[email protected]> |
3 | Date: Wed Jun 21 20:44:56 2023 +0200 |
4 | |
5 | Auto-Commit Update - 20230621 |
6 | --- |
7 | PKGBUILD | 3 +- |
8 | editenv.install | 3 + |
9 | usr/bin/enitenv | 142 +++++++++++++++++++++++++++++++++++++ |
10 | usr/share/licenses/editenv/LICENSE | 2 +- |
11 | 4 files changed, 148 insertions(+), 2 deletions(-) |
12 | |
13 | diff --git a/PKGBUILD b/PKGBUILD |
14 | index c13be53..70033a7 100644 |
15 | --- a/PKGBUILD |
16 | +++ b/PKGBUILD |
17 | @@ -7,7 +7,8 @@ pkgdesc="A simple command line tool for conveniently storing and editing environ |
18 | arch=(any) |
19 | url="https://gitlab.com/a4to/${pkgname}" |
20 | license=('MIT') |
21 | -depends=() |
22 | +depends=(dialog xsel) |
23 | +install="${pkgname}.install" |
24 | source=("git+$url.git") |
25 | sha256sums=('SKIP') |
26 | |
27 | diff --git a/editenv.install b/editenv.install |
28 | new file mode 100644 |
29 | index 0000000..0ae6c4b |
30 | --- /dev/null |
31 | +++ b/editenv.install |
32 | @@ -0,0 +1,3 @@ |
33 | +post_install() { |
34 | + echo -e "\n\033[1;32m[+]\e[0;1;37m Thank you for installing editenv\!\n\n\e[0;33m[*]\e[0;1m In order for editenv to function as intended, the following line must be added to your shells rc file:\n\n\e[1;36m source ${XDG_DATA_HOME:-$HOME/.local/share}/editenv/entries\n\e[0m" |
35 | +} |
36 | diff --git a/usr/bin/enitenv b/usr/bin/enitenv |
37 | new file mode 100755 |
38 | index 0000000..f0cbf38 |
39 | --- /dev/null |
40 | +++ b/usr/bin/enitenv |
41 | @@ -0,0 +1,142 @@ |
42 | +#!/usr/bin/env bash |
43 | + |
44 | +# Debugging: |
45 | + |
46 | +# trap 'lastCommand=$currentCommand; currentCommand=$BASH_COMMAND' DEBUG |
47 | +# trap 'echo $lastCommand' EXIT QUIT STOP ERR |
48 | + |
49 | + |
50 | +# Globals: |
51 | + |
52 | +TMP=`mktemp -qu` |
53 | + |
54 | +NEWENTRY="\\n You have not yet set any environment variables.\n\n Would you like to create one now?\\n " |
55 | + |
56 | +NOTSOURCED="\\nPlease NOTE: In order for editenv to work correctly, the entries file must be sourced from your shell's rc file.\\n\\nThis can be done by adding the following line to your bash/zshrc:\\n\\n source ${XDG_DATA_HOME:-$HOME/.local/share}/editenv/entries\\n\\n\\n\\n(It was coppied to your clipboard for your convenience)\\n\\n" |
57 | + |
58 | +ENTRIESFILE="${XDG_DATA_HOME:-$HOME/.local/share}/editenv/entries" |
59 | + |
60 | +FZFPREVIEW="cat $ENTRIESFILE|grep {} | grep -q '#YESPREVIEW' && |
61 | + cat $ENTRIESFILE | grep {}= | cut -d= -f2 | sed -r 's/\" #YESPREVIEW//;s/^\"//' | bat --style=numbers,grid --color=always && return 0 || |
62 | + cat $ENTRIESFILE | grep {} | grep -q 'NOPREVIEW' && echo -e '\n\e[1;31m |
63 | + ▗▄▄ ▗▄▄ ▗▄▄ ▗ ▖ ▗▖ ▄▄▄▖▗▄▄▖ |
64 | + ▐ ▝▌▐ ▝▌ ▐ ▝▖▗▘ ▐▌ ▐ ▐ |
65 | + ▐▄▟▘▐▄▄▘ ▐ ▌▐ ▌▐ ▐ ▐▄▄▖ |
66 | + ▐ ▐ ▝▖ ▐ ▚▞ ▙▟ ▐ ▐ |
67 | + ▐ ▐ ▘▗▟▄ ▐▌ ▐ ▌ ▐ ▐▄▄▖ |
68 | + |
69 | +\e[0m ' && return 0 || echo {} | grep -q 'NEW ENTRY' && echo -e '\n\e[1;32m[+] \e[37mCreate new environment variable\e[0m\n'" |
70 | + |
71 | +trap 'rm -f ${TMP}; eval $(source $ENTRIESFILE)' EXIT QUIT STOP ERR |
72 | + |
73 | +# Functions: |
74 | + |
75 | +PLACEHOLDER(){ echo '* NEW ENTRY' ; awk -F= '{print $1}' ${1:-$ENTRIESFILE}|sed 's/\s*//;/^$/d;s/export //g'|sort -u|grep -v 'EDITENV_ISSOURCED' ; } |
76 | + |
77 | +FIRSTLOOP(){ [ -f $ENTRIESFILE ] && [ $(cat $ENTRIESFILE | grep -v 'EDITENV_ISSOURCED' | sed '/^$/d' | wc -l) -eq 0 ] && FIRST ; } |
78 | +NOTSOURCEDLOOP(){ [[ -z $EDITENV_ISSOURCED ]] && NOTSOURCED || MAIN ; } |
79 | + |
80 | +FIRST(){ wasFirst=true ; dialog --title " ~ First Run ~ " --yesno "$NEWENTRY" 9 62 && NEW && return 0 || clear && exit 1 ; } |
81 | +NOTSOURCED(){ entries="export EDITENV_ISSOURCED=true\n$(cat $ENTRIESFILE|grep -v 'EDITENV_ISSOURCED')" ; echo -e "$entries" > $ENTRIESFILE ; dialog --title " ~ editenv ~ " --msgbox "$NOTSOURCED" 16 82 ; echo -e "source ${XDG_DATA_HOME:-$HOME/.local/share}/editenv/entries" | xsel -ib ; FIRSTLOOP ; } |
82 | + |
83 | +function NEW { |
84 | + |
85 | + ! [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/editenv" ] && |
86 | + mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/editenv" |
87 | + |
88 | + dialog \ |
89 | + --stdout --title " ~ NEW ENTRY ~ " \ |
90 | + --form "\n Please fill in the required information :\n " 13 81 3 \ |
91 | + " Entry Name :" 1 1 "" 1 16 59 0 \ |
92 | + " Entry Value :" 2 1 "" 2 16 59 0 >${TMP} |
93 | + |
94 | + ENTRYNAME=$(head -n1 ${TMP} | tail -n1) |
95 | + ENTRYVALUE=$(head -n2 ${TMP} | tail -n1) |
96 | + |
97 | + dialog \ |
98 | + --yes-label "Preview" \ |
99 | + --no-label "No Preview" \ |
100 | + --title " ~ editenv ~ " \ |
101 | + --yesno "\\n Would you like to preview this entries value upon future selection?\\n " 7 90 |
102 | + |
103 | + PREVIEW=${?} && [ ${PREVIEW} -eq "0" ] && PREVIEW="YESPREVIEW" || PREVIEW="NOPREVIEW" |
104 | + |
105 | + [[ -n $ENTRYNAME ]] && [[ -n $ENTRYVALUE ]] && echo "export ${ENTRYNAME}=\"${ENTRYVALUE}\" #${PREVIEW}" >> $ENTRIESFILE && |
106 | + notify-send "✅ Environment variables updated" && exit 0 || MAIN |
107 | + |
108 | +} |
109 | + |
110 | +function EDITORDEL { |
111 | + |
112 | + dialog \ |
113 | + --stdout --title " ~ EDIT ENV ~ " \ |
114 | + --yes-label "Edit" \ |
115 | + --no-label "Delete" \ |
116 | + --yesno "\\n Would you like to edit or delete this entry?\\n " 7 55 |
117 | + |
118 | + ACTION=${?} && [ ${ACTION} -eq "0" ] && EDIT ${VALUE} $(prev=`cat $ENTRIESFILE| grep "${VALUE}="| cut -d# -f2 | cut -b1` && [ $prev == "Y" ] || [ $prev == 'y' ] && echo "Y/n" || echo "y/N" ) || DEL ${VALUE} |
119 | + |
120 | +} |
121 | + |
122 | +function EDIT { |
123 | + |
124 | + dialog --stdout --title " ~ EDITENV ~ " \ |
125 | + --form "\n Please enter new value for $1 :\n " 12 75 3 \ |
126 | + " Entry Value :" 1 1 "" 1 18 51 0 \ |
127 | + " Preview ($2) :" 2 1 "" 2 18 51 0 >${TMP} || exit 15 |
128 | + |
129 | + ENTRYVALUE=$(head -n1 ${TMP} | tail -n1) |
130 | + PREVIEW=$(head -n2 ${TMP} | tail -n1) |
131 | + |
132 | + [[ -z $PREVIEW ]] && PREVIEW=`echo $2 | grep -q 'Y' && echo "Y" || echo "N"` |
133 | + |
134 | + [[ $PREVIEW == "n" ]] || [[ $PREVIEW == "N" ]] || [[ $PREVIEW == "No" ]] || [[ $PREVIEW == "NO" ]] && PREVIEW="NOPREVIEW" || PREVIEW="YESPREVIEW" |
135 | + [[ -n $ENTRYVALUE ]] && sed -i "s/export ${1}=.*/export ${1}=\"${ENTRYVALUE}\"#${PREVIEW}/" $ENTRIESFILE && notify-send "✅ Environment updated" && exit 0 || MAIN |
136 | + |
137 | +} |
138 | + |
139 | + |
140 | +function DEL { |
141 | + |
142 | + FIRSTLOOP && clear |
143 | + |
144 | + dialog --stdout --title " ~ DELETE ENTRY ~ " \ |
145 | + --yes-label "Delete" --no-label "Cancel" \ |
146 | + --yesno "\\n Are you sure you want to delete this entry?\\n " 7 55 |
147 | + |
148 | + [ ${?} -eq "0" ] && sed -i "/${VALUE}/d" $ENTRIESFILE && notify-send "✅ Entry Deleted" && exit 0 || MAIN |
149 | + |
150 | +} |
151 | + |
152 | +function MAIN { |
153 | + |
154 | + FIRSTLOOP && clear |
155 | + |
156 | + VALUE=$( PLACEHOLDER $1 |fzf \ |
157 | + --ansi --no-sort --no-info \ |
158 | + --prompt="Edit or add an entry: " \ |
159 | + --header " " \ |
160 | + --height 100% \ |
161 | + --preview "${FZFPREVIEW}" \ |
162 | + --preview-window=70% ) || exit 1 |
163 | + |
164 | + [[ ${VALUE} == '* NEW ENTRY' ]] && NEW && return 0 |
165 | + |
166 | + EDITORDEL && return 0 |
167 | + |
168 | +} |
169 | + |
170 | + |
171 | +# Script start: |
172 | +# --- |
173 | + |
174 | +trap "rm -f $TMP" EXIT QUIT |
175 | + |
176 | +NOTSOURCEDLOOP && case ${1} in |
177 | + '-a'|'-n'|'--add'|'--new') NEW && exit 0 ;; |
178 | + '-d'|'-r'|'--del'|'--delete'|'--remove') DEL && exit 0 ;; |
179 | + '-u'|'-p'|'-w'|'--paste'|'--write'|'--use') MAIN && trap "xdotool type --clearmodifiers `xsel -bo`" EXIT ; exit 0 ;; |
180 | + '-h'|'?'|'--help') echo -e "\n\e[1;32m Usage: \e[0m\n\n editenv [OPTION]\n\n\e[1;32m Options: \e[0m\n\n -a, -n, --add, --new\t\t\tAdd a new entry\n -d, -r, --del, --delete, --remove\tDelete an entry\n -u, -p, -w, --paste, --write, --use\tImmediately paste the selected entry\n -h, ?, --help\t\t\t\tDisplay this help and exit\n" ;; |
181 | + *) MAIN && [[ -n $wasFirst ]] && dialog --title " ~ First Run ~ " --msgbox "You have successfully created your first entry.\\n\\nNote, that if you want to immediately paste the selected entry, intead of just copying it to the clipboard, you can use the -w option.\\n\\nFor more information, use the -h option." 10 80 && exit 0 || exit 0 ;; |
182 | +esac |
183 | + |
184 | diff --git a/usr/share/licenses/editenv/LICENSE b/usr/share/licenses/editenv/LICENSE |
185 | index 276f429..9f66f80 100644 |
186 | --- a/usr/share/licenses/editenv/LICENSE |
187 | +++ b/usr/share/licenses/editenv/LICENSE |
188 | @@ -1,7 +1,7 @@ |
189 | MIT/X Consortium License |
190 | |
191 | Creator /Maintainer : |
192 | -© 2020-2022 Connor Etherington <[email protected]> |
193 | +© Connor Etherington <[email protected]> |
194 | --------------------------------------------------------------------------- |
195 | Contributors: |
196 | |