forked from tzarskyz/dotfiles-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_functions
More file actions
79 lines (74 loc) · 1.83 KB
/
bash_functions
File metadata and controls
79 lines (74 loc) · 1.83 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
# Use ack to search my history file; pipe to less if necessary
hack()
{
var=$(history | ack $1 | grep -v 'bin/ack' | wc -l)
if (( $var > 22 ))
then
history | ack $1 | grep -v hack | less
else
history | ack $1 | grep -v hack
fi
}
# Use ack to search output of ps ax; pipe to less if necessary
pack()
{
var=$(ps ax | ack $1 | grep -v 'bin/ack' | wc -l)
if (( $var > 22 ))
then
ps ax | ack $1 | grep -v 'bin/ack' | less
else
ps ax | ack $1 | grep -v 'bin/ack'
fi
}
# start mpd if it's not already running
mp_start() {
count=$(ps -c | grep mpd | wc -l)
if (( $count > 0 ))
then
mpd --no-daemon &
# mpdscribble --no-daemon &
mpc clear
fi
}
mycc() {
output=${2:-"${1%.c}"}
clang -Wall -W -pedantic -std=c99 -o "$output" "$1"
}
# ksh-style "cd old new" for bash
# "ccd old new" replaces old with new throughout $PWD and then tries
# to cd to the new path
#
# This works very well for eg $HOME/mmt/2010/compsci2/grades ->
# $HOME/mmt/2010/compsci3/grades which I have to do constantly
#
# Shamelessly stolen from Learning the Bash Shell (3ed), Cameron Newham
# & Bill Rosenblatt
ccd() {
case "$#" in
0|1)
builtin cd $1
;;
2)
newdir=${PWD//$1/$2}
case "$newdir" in
$PWD)
echo "ccd: bad substitution" >&2
return 1
;;
*)
builtin cd "$newdir"
pwd
;;
esac
;;
*)
echo "ccd: wrong arg count" 1>&2
return 1
;;
esac
}
## See https://twitter.com/#!/mlafeldt/status/192195940164173824
# Get the absolute directory, symlinks resolved
realdir() {
( cd -P -- "${1:-.}" && pwd )
}