-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.sh
119 lines (110 loc) · 2.36 KB
/
functions.sh
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
119
#!/bin/sh
#
# My collection of user functions
#
mkdircd(){
mkdir "$1" && cd "$1"
}
ge() {
if [ -z "$DISPLAY" ] ; then
if [ -n "${EDITOR:-}" ] && type $EDITOR ; then
$EDITOR "$@"
return $?
fi
if type micro ; then
micro "$@"
return $?
fi
vi "$@"
return $?
fi
if type wmctrl >/dev/null 2>&1 ; then
local appwin=$(wmctrl -l -x | awk '$3 == "geany.Geany" { print $1}')
if [ -n "$appwin" ] ; then
echo "Activating running geany..."
wmctrl -i -R "$appwin"
geany "$@"
else
echo "Starting geany..."
geany "$@" >> $HOME/.xsession-errors 2>&1 &
fi
return 0
fi
geany "$@" &
}
screen() {
command screen "$@"
rc=$?
tput cup $(tput lines) 0
return $rc
}
pkglst() {
xbps-query -m | awk -F- -v OFS=- '{ $NF="" ; NF=NF-1; print}' | sort -u
}
pkgdiff() {
local t=$(mktemp)
pkglst > $t
diff -u /var/log/install-pkgs.txt $t | grep -v '^ ' | grep -v '^@'
rm -f $t
}
git_local_user() {
[ $# -eq 0 ] && set - '--work'
local mode name email
while [ $# -gt 0 ]
do
case "$1" in
--work) mode='work' ; name='Alejandro Liu' ; email='alejandrol@t-systems.com' ;;
--personal) mode='personal' ; name='Alejandro Liu' ; email='alejandro_liu@hotmail.com' ;;
*)
echo 'Usage: $0 [--work|--personal]'
return 0
esac
shift
done
if [ ! -d '.git' ] ; then
echo 'You must be a the root of a git repository when you run this command.'
return 1
fi
echo 'Currently configure user' 1>&2
local yn
for yn in user.name user.email
do
git config --show-origin --get $yn 1>&2
done
echo -n 'Configure local $mode addresses? (y/N) ' 1>&2
read yn
case "$yn" in
y*|Y*)
echo 'Configuring local addresses' 1>&2
git config user.name "$name" || return 1
git config user.email "$email" || return 1
return 0
;;
*)
echo 'Aborting' 1>&2
return 1
;;
esac
}
widen() {
printf "\x1B[8;40;132t"
}
git() {
command git "$@"
local ret=$?
if [ x"$1" = x"clone" ] && [ $ret -eq 0 ] ; then
# Determine the new clone location
local dir=
eval local i=\"\$$#\"
if [ -d "$i" ] ; then
dir="$i"
elif [ -d "$(basename "$i" '.git')" ] ; then
dir="$(basename "$i" '.git')"
else
echo "Unable to determine clone directory" 1>&2
return $ret
fi
echo "CLONED: $dir"
fi
return $ret
}