| Hash | Commit message | Author | Date | Files | + | - |
1 | commit d312ef4d35722d18f840c5b9026f6f9d32ee799f |
2 | Author: Connor Etherington <[email protected]> |
3 | Date: Sun May 22 22:02:33 2022 +0200 |
4 | |
5 | Update. |
6 | --- |
7 | PKGBUILD | 4 +-- |
8 | usr/bin/qcopy | 76 ++++++++++++++++++++++++++++++++++++++++++++ |
9 | usr/share/doc/qcopy/.gitkeep | 0 |
10 | 3 files changed, 78 insertions(+), 2 deletions(-) |
11 | |
12 | diff --git a/PKGBUILD b/PKGBUILD |
13 | index 80599f8..d5a75b2 100644 |
14 | --- a/PKGBUILD |
15 | +++ b/PKGBUILD |
16 | @@ -3,11 +3,11 @@ |
17 | pkgname=qcopy |
18 | pkgver=1.0 |
19 | pkgrel=1 |
20 | -pkgdesc="Easily set and copy values from a selection of defined variables/placeholders" |
21 | +pkgdesc="Easily set variables and their respective values for easy access at any point" |
22 | arch=(any) |
23 | url="https://gitlab.com/a4to/${pkgname}" |
24 | license=('MIT') |
25 | -depends=(fzf dialog xclip) |
26 | +depends=(fzf dialog xclip bat) |
27 | source=("git+$url.git") |
28 | sha256sums=('SKIP') |
29 | |
30 | diff --git a/usr/bin/qcopy b/usr/bin/qcopy |
31 | new file mode 100755 |
32 | index 0000000..f504a58 |
33 | --- /dev/null |
34 | +++ b/usr/bin/qcopy |
35 | @@ -0,0 +1,76 @@ |
36 | +#!/usr/bin/env bash |
37 | + |
38 | +# Debugging: |
39 | + |
40 | +# trap 'lastCommand=$currentCommand; currentCommand=$BASH_COMMAND' DEBUG |
41 | +# trap 'echo $lastCommand' EXIT QUIT STOP ERR |
42 | + |
43 | + |
44 | +# Global Variables: |
45 | + |
46 | +NEWENTRY="\\n You have not yet set any qcopy variables. Would you like to create one now?\\n " |
47 | + |
48 | +ENTRIESFILE="${XDG_DATA_HOME:-$HOME/.local/share}/qcopy/entries" |
49 | + |
50 | +TMP=`mktemp -qu` |
51 | + |
52 | + |
53 | + |
54 | +# Functions: |
55 | + |
56 | +PLACEHOLDER(){ awk -F= '{print $1}' ${1:-$ENTRIESFILE}|sed 's/\s*//;/^$/d'|sort -u ; } |
57 | + |
58 | +FIRSTLOOP(){ [ -f $ENTRIESFILE ] && [ $(cat $ENTRIESFILE | wc -w) -ge 1 ] || FIRST ; } |
59 | + |
60 | +FIRST(){ dialog --title " ~ First Run ~ " --yesno "$NEWENTRY" 8 82 && NEW && return 0 || clear && exit 1 ; } |
61 | + |
62 | + |
63 | + |
64 | +function NEW { |
65 | + |
66 | + ! [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/qcopy" ] &&[41m |
67 | + mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/qcopy" |
68 | +[41m |
69 | + dialog \ |
70 | + --stdout --title " ~ NEW ENTRY ~ " \ |
71 | + --form "\n Please fill in the required information :\n " 13 81 3 \ |
72 | + " Entry Name :" 1 1 "" 1 16 59 0 \ |
73 | + " Entry Value :" 2 1 "" 2 16 59 0 >${TMP} |
74 | + |
75 | + ENTRYNAME=$(head -n1 ${TMP} | tail -n1) |
76 | + ENTRYVALUE=$(head -n2 ${TMP} | tail -n1) |
77 | +[41m |
78 | + [[ -n $ENTRYNAME ]] && [[ -n $ENTRYVALUE ]] && |
79 | + echo "${ENTRYNAME}=${ENTRYVALUE}" >> $ENTRIESFILE || MAIN && exit 0 |
80 | + |
81 | +}[41m |
82 | + |
83 | +function MAIN { |
84 | + |
85 | + FIRSTLOOP && clear |
86 | + |
87 | + VALUE=$( PLACEHOLDER $1 |fzf \ |
88 | + --multi --ansi --no-sort --no-info \ |
89 | + --prompt="Please select :" \ |
90 | + --header " " \ |
91 | + --height 99% \ |
92 | + --preview="cat $ENTRIESFILE|grep {}|cut -d= -f2-|bat --style=numbers,grid --color=always" \ |
93 | + --preview-window=70% ) || exit 1 |
94 | + |
95 | + cat $ENTRIESFILE| grep "${VALUE}"| awk -F= '{print $2}'| sed 's/\s*//g'| xclip -selection clipboard -i |
96 | + |
97 | +} |
98 | + |
99 | + |
100 | +# Script start: |
101 | +# --- |
102 | + |
103 | +trap "rm -f $TMP" EXIT QUIT |
104 | + |
105 | +FIRSTLOOP && case ${1} in |
106 | + '-a'|'-n'|'--add'|'--new')[41m |
107 | + NEW && MAIN && exit 0 ;; |
108 | + *) MAIN && exit 0 ;; esac |
109 | +[41m |
110 | +MAIN && exit 0 |
111 | + |
112 | diff --git a/usr/share/doc/qcopy/.gitkeep b/usr/share/doc/qcopy/.gitkeep |
113 | deleted file mode 100644 |
114 | index e69de29..0000000 |