forked from justone/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bash_functions.sh
43 lines (37 loc) · 984 Bytes
/
.bash_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
#! /bin/bash
code_dir="$HOME/code"
function print_code_branches {
for dir in $(ls $code_dir) ; do
dir="$code_dir/$dir"
if [ -d $dir ]; then
git -C $dir rev-parse 2> /dev/null
if [[ $? -eq 0 ]]; then
branch_name=`git -C $dir rev-parse --abbrev-ref HEAD 2>/dev/null`
echo -e "$(basename $dir):\e[32m$branch_name \e[39m"
fi
fi
done
}
code_fzf() {
dir=$(print_code_branches |
fzf --layout=reverse --ansi |
cut -d: -f1)
if [[ ${dir} != "" ]]; then
clear
cd ${code_dir}/${dir}
fi
}
function today {
TODAY_DIR="$HOME/today/"
DATE_DIR=$(date +'%Y-%m-%d')
if [ ! -d $TODAY_DIR$DATE_DIR ];
then
mkdir -p $TODAY_DIR$DATE_DIR
fi;
echo $TODAY_DIR$DATE_DIR
}
# add a binding if we are in an interactive shell
if [[ $- =~ i ]]; then
bind '"\C-g\C-t": "$(today)\e\C-e"'
bind '"\C-g\C-w": "code_fzf\n"'
fi