-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdprintf
77 lines (65 loc) · 1.84 KB
/
dprintf
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
## dprintf - dprint to print queue
## Copyleft 11/03/2016
## last modified 03/16/2018
## Usage dprintf <file>
function mypath () {
## Get the real path of the calling script
## From: https://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within/246128#246128
my_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
}
debug_out="/dev/stderr" ## debug - so debug output always has somewhere to go
##debug_out="$HOME/temp/debug_output_dprintf.txt" ## debug
##exec 5> "$debug_out" ## debug
##BASH_XTRACEFD="5" ## debug
##source "${HOME}/bin/bash_trace" ## debug - TRACE
name="${0##*/}"
##echo "name is $name" > "${debug_out}" ## debug
usage="Usage ${name} [dprint options] file"
script_error=9
mypath
script_path="${my_path}" ## make sure we can find other scripts
##echo "script_path is $script_path" >> "${debug_out}" ## debug
## from https://www.cyberciti.biz/faq/linux-unix-bsd-apple-osx-bash-get-last-argument/
for last in "$@"; do :; done ## Get last argument to script
if [[ ! -r "${last}" ]] ## file name is last parameter
then
echo "$usage"
exit 1
fi
config="${HOME}/.duplexpr"
## Access the duplexpr configuration file
if [[ ! -r $config ]] ## debug
then
echo "Missing config file ${config}"
exit "${script_error}"
fi
source "${config}"
if (( $? ))
then
echo "Bad config file ${config}"
exit "${script_error}"
fi
"${script_path}"/pqnext -q ## Get next file name in clipboard without displaying anything
rc=$?
if (( rc ))
then
echo "pqnext failed with error code ${rc}"
exit $rc
fi
## Must have xclip
hash xclip 2>/dev/null
rc=$?
if (( rc ))
then
echo "xclip isn't installed"
exit "${script_error}"
fi
num="$(xclip -selection clipboard -o)"
rc=$?
if (( rc ))
then
echo "xclip failed with error code ${rc}"
exit $rc
fi
"${script_path}"/dprint -o "$pq/$num" "$@"