-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_functions
More file actions
118 lines (98 loc) · 2.63 KB
/
Copy pathbash_functions
File metadata and controls
118 lines (98 loc) · 2.63 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
# Functions to help us manage paths. Second argument is the name of the
# path variable to be modified (default: PATH)
function pathremove {
local IFS=':'
local NEWPATH
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export $PATHVARIABLE="$NEWPATH"
}
function pathprepend {
pathremove "$1" "$2"
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}
function pathappend {
pathremove "$1" "$2"
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}
function load_cdpath {
local CDPATH_CONF=.cdpath
CDPATH=.
if [ -f ${CDPATH_CONF} ]; then
while read dir; do
pathappend "${dir}" CDPATH
done < ${CDPATH_CONF}
fi
export CDPATH
}
function pathlist {
local IFS=':'
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
echo "${DIR}"
done
}
# Functions to help us source files in bash. Not really necessary, but it
# streamlines some branches
function sourceconf {
if [ -f "$1" ]; then
source "$1"
fi
}
function sourceconf-noposix {
if [ -f "$1" ] && ! shopt -oq posix; then
source "$1"
fi
}
# What am i???? What have I become???
function is_osx {
test "$OS" = Darwin
}
function is_linux {
test "$OS" = Linux
}
if is_osx; then
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
#alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# # Display files in Quick Look
# function ql () {
# (qlmanage -p “$@” > /dev/null 2>&1 &
# local ql_pid=$!
# read -sn 1
# kill ${ql_pid}) > /dev/null 2>&1
# }
# # Display any filetype as plain text
# function qlt () {
# (qlmanage -p -c public.plain-text “$@” > /dev/null 2>&1 &
# local ql_pid=$!
# read -sn 1
# kill ${ql_pid}) > /dev/null 2>&1
# }
function unquarantine {
xattr -d -r -v com.apple.quarantine "$@"
}
function addgroup {
if [ $# -ne 2 ]; then
echo -e "Adds user to group.\n\tUsage: addgroup USER GROUP"
return 1
fi
/usr/sbin/dseditgroup -o edit -a $1 -t user $2
}
function removegroup {
if [ $# -ne 2 ]; then
echo -e "Removes user from group.\n\tUsage: addgroup USER GROUP"
return 1
fi
/usr/sbin/dseditgroup -o edit -d $1 -t user $2
}
fi