forked from Worldie-com/pen.el
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmd-nice-posix
More file actions
executable file
·36 lines (28 loc) · 922 Bytes
/
cmd-nice-posix
File metadata and controls
executable file
·36 lines (28 loc) · 922 Bytes
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
#!/bin/bash
export TTY
while [ $# -gt 0 ]; do opt="$1"; case "$opt" in
"") { shift; }; ;;
-nbs) {
export NOBS=y
shift
}
;;
*) break;
esac; done
# This is primarily designed for posix shell double-quote escapes.
# If other languages can use this, then great.
cmd-nice() {
for var in "$@"
do
# A grand test of this is that it's idempotent with myeval
# myeval cmd-nice "$(cmd-nice "hi ")"
# Remember that some chars escape differently
# pl "\$"
# pl "\)"
# It might be too hairy to capture all these rules for the moment
# printf '"%s" ' "$(printf %s "$var" | sed 's/\(\\*\)"/\1\1\\"/g')";
# TODO Ensure that the first \ to touch the non-" is not doubled?
printf '"%s" ' "$(printf %s "$var" | sed 's/\(\\\)\([^"]\|$\)/\1\1\2/g' | sed 's/\(\\*\)"/\1\1\\"/g')";
done | sed 's/ $//'
}
cmd-nice "$@"