-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfunctions.bash
executable file
·56 lines (51 loc) · 1.04 KB
/
functions.bash
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
function hasBinary {
hash "$1" 2>/dev/null
}
function hasBinaryInLinux {
if ! $WSL; then
hasBinary "$1"
return
fi
PATH=`removeWindowsFromPath` hash "$1" 2>/dev/null
}
function man {
case "$(type -t -- "$1")" in
builtin|keyword)
help -m "$1" | less
;;
*)
command man "$@"
;;
esac
}
function edit-var {
declare -n VAR=$1
if ! [ -v VAR ]; then
echo "Variable with name '${!VAR}' does not exist."
return
fi
local TMP
TMP=`mktemp`
echo "${VAR}" > "$TMP"
vim "$TMP"
eval "${!VAR}"'=`cat '"$TMP"'`'
rm "$TMP"
}
function lorem {
if [ -z "$1" ]; then
PARAGRAPHS=10
else
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "Usage: lorem <number of paragraphs>"
return
fi
PARAGRAPHS=$1
fi
perl -e 'use Text::Lorem;my $text = Text::Lorem->new();$paragraphs = $text->paragraphs('"$PARAGRAPHS"');print $paragraphs;'
}
function watchrun {
while inotifywait -q -e close_write "$1"; do
# shellcheck disable=SC2092
`realpath "$1"`
done
}