-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
91 lines (79 loc) · 2.24 KB
/
.functions
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
#!/bin/bash
# useful routines
# run program, ignore output and return prompt immediately
run() {
setsid $1 &> /dev/null
}
# terminate process by name
k() {
killall $1
}
# open file, ignore output and return prompt immediately
go() {
xdg-open "$@" &> /dev/null
}
# lock screen and put computer to sleep
zzz() {
gnome-screensaver-command -l
dbus-send --system --print-reply \
--dest="org.freedesktop.UPower" \
/org/freedesktop/UPower \
org.freedesktop.UPower.Suspend &> /dev/null
}
# reparent a program to a new terminal
rep() {
# give temporary full scope to ptrace
sudo su -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope"
# reparent process PID under current terminal
reptyr `pidof $1`
}
# check spelling (f->french, default is english)
s() {
word=$1
option=''
if [ $1 == 'f' ]; then
option="-l fr"
word=$2
fi
result="$(echo $word | aspell $option -a | tail -n 2)"
if [ "$result" == "*" ]; then
echo "OK"
elif [ $(echo $result | grep "&" | wc -l) != 0 ]; then
echo $result | sed "s|& $word \([0-9]\+\) [0-9]\+: |\1 suggestions:\n|"
else
echo "Unknown word"
fi
}
# dictionary lookup (f->french, t->translate, default is english)
#TODO: highlight occurences of searched word
# add colors (eg: type of word...), change format, check less options
# fix annoying glitch with suggestions in less
sd() {
word=$1
option=''
if [ $1 == 'f' ] || [ $1 == 't' ]; then
option=$1
word=$2
fi
export STARDICT_DATA_DIR=/usr/share/"$option"stardict
sdcv $word | less
}
# update music folder and cmus lib with recent downloads
mu() {
mv -i ~/Downloads/*.mp3 ~/Music/ &> /dev/null
#check cmus socket is open, if so update lib
if [ "$(ls -a ~/.cmus/ | grep socket | wc -l)" != 0 ]; then
cmus-remote -l ~/Music/
fi
}
# load music into specified mobile player (need to mount android..)
#TODO: option to specify target storage media
# option to specify source playlist
ml() {
mkdir -p ~/Desktop/tmpzik/
#each line in source playlist is a path to a music file
while read p; do
"cp" "$p" ~/Desktop/tmpzik/
done <~/.cmus/playlist.pl
echo "still working on this"
}