-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass
executable file
·35 lines (27 loc) · 839 Bytes
/
pass
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
#!/bin/sh
# Quit if file not given
[[ ! $1 ]] && exit
# If given a 2nd argument print only the line matching
if [[ $2 ]]; then
# Select the last word of the line matching
output=$(dec $1 | awk 'BEGIN{IGNORECASE=1} /'$2'/{printf $NF}')
if [[ "$output" != "" ]]; then
# Use "-loops 2" instead of 1 because with 1 it doesn't work on
# graphical applications for some reason
echo -n $output | xclip -loops 2 -selection primary -i
# Erase the selection after 5 seconds to make sure the data
# does not ever stay in the selection
(
sleep 5
echo -n | xclip -selection primary -i
which notify-send >/dev/null &&
notify-send --expire-time=2000 "Clipboard" "X11 selection cleared"
) &
echo "Copied to X11 selection for one time use."
else
echo "No match found."
fi
else
# Print the whole file
dec $1
fi