-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc
More file actions
129 lines (104 loc) · 2.78 KB
/
.bashrc
File metadata and controls
129 lines (104 loc) · 2.78 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
119
120
121
122
123
124
125
126
127
128
129
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
if [ "$TERM" == "screen" ]; then
# Screen doesn't load .bash_profile?
. $DOTFILES_PATH/.bash_profile
fi
# Load auxiliary configurations
load_files=(~/.bash_private ~/.bash_aliases)
for f in ${load_files[@]}; do
if [ -f $f ]; then
source $f
fi
done
# Helper functions
function c () { # Substitute for `cd`
cd *${*}*
pwd
ls
}
function f () { # Find file in cwd
find . -name "*$**"
}
function fcd() { # Find directory under cwd and cd into it
target=$(find . -name "*$**" -type d | head -n1)
if [ $target ]; then
cd $target
else
echo "Directory not found: $*"; return
fi
}
function p () { # Find process
ps aux | grep "$*"
}
function g () { # Grep in cwd
grep -Ir "$(echo $*)" .
}
function gg () { # Double-grep (grep with files resulting of the first grep)
grep -Irl ${1} . | xargs grep -I ${2}
}
function greplace () { # Grep in cwd and replace $1 with $2 in-line
grep -Irl "$1" . | while read i; do
echo "Replacing: $i"
perl -p -i -e "s/$1/$2/g" "$i"
done
}
function mailfile() { # Send file to a given email address as attachment
# uuenview can be replaced with uuencode (bin depends on the distro)
uuenview "$1" | mail -s "$(basename $1)" $2
}
function bak() { # Move target to *.bak
t=$1;
if [ "${t:0-1}" = "/" ]; then
t=${t%%/}; # Strip trailing / of directories
fi
mv -v $t{,.bak}
}
function unbak() { # Revert previously bak'd target
t=$1;
if [ "${t:0-1}" = "/" ]; then
t="${t%%/}"; # Strip trailing / of directories
fi
if [ "${t:0-4}" = ".bak" ]; then
mv -v "$t" "${t%%.bak}"
else
echo "No .bak extension, ignoring: $t"
fi
}
if [ ! "$(which say)" ]; then
function say() { echo "$*" | festival --tts; }
fi
function vmod() { # Open modified git files usin `v`
v $(git status | grep 'modified:' | cut -d ' ' -f4 | xargs);
}
function w() { watch -dn1 $*; }
# Workspace navigation functions
function go() { # Jump to a project (and activate environment)
to=$1
if [ ! "$to" ]; then
# Go to the last go'ne destination
to=$(grep "^go " ~/.bash_history | tail -n1 | cut -d ' ' -f2-)
fi
cd ~/projects/$to
# Load project profile (e.g. virtualenv)
[ -e .profile ] && . .profile
}
function up() { # cd to root of repository
old_pwd="$PWD";
while [ 1 ]; do
cd ..
if [ "$PWD" == "/" ]; then
cd "$old_pwd"
echo "No repository found, returned to $PWD"
return 1
fi
for repo in ".git" ".hg"; do
if [ -d "$repo" ]; then
echo "Found $repo at $PWD"
return 0;
fi
done
done
}