-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfass
executable file
·60 lines (56 loc) · 1.44 KB
/
fass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
#set -x
source "${HOME}/.BASH_ENV"
if [[ "$1" == "-c" || "$1" == "--clip" ]]
then
TOCLIP=true
shift
elif [[ "$1" == "-t" || "$1" == "--type" ]]
then
TYPE=true
shift
TERMINATOR=''
if [[ "$1" == "-n" || "$1" == "-t" ]]
then
TERMINATOR="$1"
shift
fi
else
if [[ $(basename "$0") == "fassc" ]]; then
TOCLIP=true
fi
fi
SEARCH="$1"
shift
if [[ "${SEARCH}" == "-" ]]
then
SEARCH=''
fi
# Choose the pass-file
passfile=$(pass-file-chooser "${SEARCH}")
if [[ -n ${passfile} ]]; then
if [[ "$@" == "" || $1 == -* ]]; then
cmd=show
else
cmd=$1
shift
fi
# if invoked via fassc symlink then send result to clipboard
if [[ "${TOCLIP}" == "true" ]]
then
# Copy requested data to the clipboard (auto clean in 45 seconds)
nohup pass ${cmd} "${@}" "${passfile}" --clip &>/dev/null &
echo "Copied requested data from the ${passfile} to clipboard. The copied data will be discarded from the clipboard in a minute or so"
else
# Get the data
RESULT=$(pass ${cmd} "${@}" "${passfile}")
if [[ "${TYPE}" == "true" ]]
then
# Send the result to the keyboard buffer (e.g. type URL in the browser's search bar
nohup type-command --type "${TERMINATOR}" "${RESULT}" &>/dev/null &
else
# Send the result to the stdout
echo "${RESULT}"
fi
fi
fi