| Hash | Commit message | Author | Date | Files | + | - |
1 | commit 9420207caa1a3328388a26c4146fc2b918b94fe1 |
2 | Author: Connor Etherington <[email protected]> |
3 | Date: Sat Jun 24 05:38:13 2023 +0200 |
4 | |
5 | Auto-Commit Update - 20230624 |
6 | --- |
7 | PKGBUILD | 2 +- |
8 | usr/bin/editenv | 54 ++++++++++++++++++++++++++++++++++++++++++++---------- |
9 | 2 files changed, 45 insertions(+), 11 deletions(-) |
10 | |
11 | diff --git a/PKGBUILD b/PKGBUILD |
12 | index 6be7e5a..177f5f6 100644 |
13 | --- a/PKGBUILD |
14 | +++ b/PKGBUILD |
15 | @@ -1,7 +1,7 @@ |
16 | # Maintainer: Connor Etherington <[email protected]> |
17 | # --- |
18 | pkgname=editenv |
19 | -pkgver=0.1.0 |
20 | +pkgver=0.1.1 |
21 | pkgrel=1 |
22 | pkgdesc="A simple command line tool for conveniently storing and editing environment variables." |
23 | arch=(any) |
24 | diff --git a/usr/bin/editenv b/usr/bin/editenv |
25 | index f0cbf38..a475d81 100755 |
26 | --- a/usr/bin/editenv |
27 | +++ b/usr/bin/editenv |
28 | @@ -1,4 +1,4 @@ |
29 | -#!/usr/bin/env bash |
30 | +#!/usr/bin/env sh |
31 | |
32 | # Debugging: |
33 | |
34 | @@ -29,15 +29,33 @@ FZFPREVIEW="cat $ENTRIESFILE|grep {} | grep -q '#YESPREVIEW' && |
35 | |
36 | trap 'rm -f ${TMP}; eval $(source $ENTRIESFILE)' EXIT QUIT STOP ERR |
37 | |
38 | + |
39 | # Functions: |
40 | |
41 | +err(){ echo -e "${*}" && exit 1 ; } |
42 | + |
43 | PLACEHOLDER(){ echo '* NEW ENTRY' ; awk -F= '{print $1}' ${1:-$ENTRIESFILE}|sed 's/\s*//;/^$/d;s/export //g'|sort -u|grep -v 'EDITENV_ISSOURCED' ; } |
44 | |
45 | +SELECTHOLDER(){ awk -F= '{print $1}' ${1:-$ENTRIESFILE}|sed 's/\s*//;/^$/d;s/export //g'|sort -u|grep -v 'EDITENV_ISSOURCED' ; } |
46 | + |
47 | FIRSTLOOP(){ [ -f $ENTRIESFILE ] && [ $(cat $ENTRIESFILE | grep -v 'EDITENV_ISSOURCED' | sed '/^$/d' | wc -l) -eq 0 ] && FIRST ; } |
48 | -NOTSOURCEDLOOP(){ [[ -z $EDITENV_ISSOURCED ]] && NOTSOURCED || MAIN ; } |
49 | + |
50 | +NOTSOURCEDLOOP(){ [[ -z $EDITENV_ISSOURCED ]] && NOTSOURCED ; } |
51 | |
52 | FIRST(){ wasFirst=true ; dialog --title " ~ First Run ~ " --yesno "$NEWENTRY" 9 62 && NEW && return 0 || clear && exit 1 ; } |
53 | -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 ; } |
54 | + |
55 | +COPYVAL(){ cat $ENTRIESFILE | grep "${1}" | cut -d\" -f2 | cut -d# -f1 | xsel -ib && notify-send "${2}" ; } |
56 | + |
57 | +QUICKADD(){ [[ -n $2 ]] && echo 'export '$1'="'$2'" #YESPREVIEW' >> $ENTRIESFILE && notify-send "✅ Environment updated" && exit 0 ; } |
58 | + |
59 | +NOTSOURCED(){ |
60 | + |
61 | + entries="export EDITENV_ISSOURCED=true\n$(cat $ENTRIESFILE|grep -v 'EDITENV_ISSOURCED')" ; |
62 | + |
63 | + echo -e "$entries" > $ENTRIESFILE ; dialog --title " ~ editenv ~ " --msgbox "$NOTSOURCED" 16 82 ; |
64 | + echo -e "source ${XDG_DATA_HOME:-$HOME/.local/share}/editenv/entries" | xsel -ib ; FIRSTLOOP ; |
65 | + |
66 | +} |
67 | |
68 | function NEW { |
69 | |
70 | @@ -81,7 +99,7 @@ function EDITORDEL { |
71 | function EDIT { |
72 | |
73 | dialog --stdout --title " ~ EDITENV ~ " \ |
74 | - --form "\n Please enter new value for $1 :\n " 12 75 3 \ |
75 | + --form "\n Please enter new value for $1 :\n " 12 75 3 \ |
76 | " Entry Value :" 1 1 "" 1 18 51 0 \ |
77 | " Preview ($2) :" 2 1 "" 2 18 51 0 >${TMP} || exit 15 |
78 | |
79 | @@ -100,11 +118,13 @@ function DEL { |
80 | |
81 | FIRSTLOOP && clear |
82 | |
83 | + cat $ENTRIESFILE | grep -q "${1}=" || err "\n[-][0;1m No variable exists with the name \"${1}\"[0m"; |
84 | + |
85 | dialog --stdout --title " ~ DELETE ENTRY ~ " \ |
86 | --yes-label "Delete" --no-label "Cancel" \ |
87 | --yesno "\\n Are you sure you want to delete this entry?\\n " 7 55 |
88 | |
89 | - [ ${?} -eq "0" ] && sed -i "/${VALUE}/d" $ENTRIESFILE && notify-send "✅ Entry Deleted" && exit 0 || MAIN |
90 | + [ ${?} -eq "0" ] && sed -i "/${1}/d" $ENTRIESFILE && notify-send "✅ Entry Deleted" && exit 0 || MAIN |
91 | |
92 | } |
93 | |
94 | @@ -126,17 +146,31 @@ function MAIN { |
95 | |
96 | } |
97 | |
98 | +function SELECT { |
99 | + |
100 | + [[ -n $2 ]] && VALUE=$2 || VALUE=$( SELECTHOLDER |fzf \ |
101 | + --ansi --no-sort --no-info \ |
102 | + --prompt="${1} " \ |
103 | + --header " " \ |
104 | + --height 100% \ |
105 | + --preview "${FZFPREVIEW}" \ |
106 | + --preview-window=70% ) || exit 1 |
107 | + |
108 | + echo ${VALUE} |
109 | +} |
110 | + |
111 | + |
112 | |
113 | # Script start: |
114 | # --- |
115 | |
116 | trap "rm -f $TMP" EXIT QUIT |
117 | |
118 | -NOTSOURCEDLOOP && case ${1} in |
119 | - '-a'|'-n'|'--add'|'--new') NEW && exit 0 ;; |
120 | - '-d'|'-r'|'--del'|'--delete'|'--remove') DEL && exit 0 ;; |
121 | - '-u'|'-p'|'-w'|'--paste'|'--write'|'--use') MAIN && trap "xdotool type --clearmodifiers `xsel -bo`" EXIT ; exit 0 ;; |
122 | - '-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" ;; |
123 | +case ${1} in |
124 | + '-a'|'-n'|'--add'|'--new') [[ -n $3 ]] && QUICKADD "$2" "$3" || NEW && exit 0 ;; |
125 | + '-c'|'-y'|'--copy'|'--yes') x="${@:2}"; COPYVAL "${x:-`SELECT "Select value to copy:"`}" "✅ Copied to clipboard" && exit 0 ;; |
126 | + '-d'|'-r'|'--del'|'--delete'|'--remove') x="${@:2}"; DEL "${x:-`SELECT "Select entry for removal:"`}" && exit 0 ;; |
127 | + '-h'|'--help') echo -e "\n\e[1;32m Usage: \e[0m\n\n\e[33m $(basename $0)\e[0;1m [OPTIONS]\n\n \e[35m -a, --add:\e[0m Add a new entry.\n \e[35m -n, --new:\e[0m Alias for -a or --add.\n \e[35m -c, --copy:\e[0m Copy a value to the clipboard.\n \e[35m -y, --yes:\e[0m Alias for -c or --copy.\n \e[35m -d, --del:\e[0m Delete an entry.\n \e[35m -r, --remove:\e[0m Alias for -d or --del.\n \e[35m -h, --help: \e[0mDisplay this help message.\n\n\n\e[1;32m Examples: \e[0m\n\n \e[33m $(basename $0)\e[35m -a \e[36mvariable_name \"Env variable value\"\e[32m Add a new environment variable.\n \e[33m $(basename $0) \e[35m-c \e[36mvariable_name \e[32mCopy the value of a variable to the clipboard.\e[0m\n \e[33m $(basename $0) \e[35m-d \e[36mvariable_name \e[32mDelete an environment variable.\e[0m\n\n" ;; |
128 | *) 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 ;; |
129 | esac |
130 | |