-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.sh
111 lines (100 loc) · 2.9 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
#############
# Functions #
#############
# Count code in a directory
# Usage: code_count <directory> <file extension>
# Example: code_count src/ js
code_count() {
if [ "$#" -ne 2 ]; then
echo "Usage: code_count <directory> <file extension>"
return 1
fi
echo "$(find "$1" -type f -iname *."$2" | xargs wc -l | sort)"
}
# Make a gif!
gifify() {
if [[ -n "$1" ]]; then
if [[ $2 == '--good' ]]; then
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $1.gif
rm out-static*.png
else
ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $1.gif
fi
else
echo "proper usage: gifify <input_movie.mov>. You DO need to include extension."
fi
}
# Make a directory and cd into it
mkcd() {
mkdir -p $1;
cd $1;
}
# FZF git branch checkout helper
fzf_gitcheckout() {
local branches branch
branches=$(git branch -vv) &&
branch=$(echo "$branches" | fzf +m) &&
git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
# FZF git commit checkout helper
fzf_gitcommit() {
local commits commit
commits=$(git log --pretty=oneline --abbrev-commit --reverse) &&
commit=$(echo "$commits" | fzf --tac +s +m -e) &&
git checkout $(echo "$commit" | sed "s/ .*//")
}
# FZF git commit hash selector
fzf_gitcommithash() {
local commits commit
commits=$(git log --color=always --pretty=oneline --abbrev-commit --reverse) &&
commit=$(echo "$commits" | fzf --tac +s +m -e --ansi --reverse) &&
echo -n $(echo "$commit" | sed "s/ .*//")
}
# FZF git stash helper
fzf_gitstash() {
local out q k sha
while out=$(
git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" |
fzf --ansi --no-sort --query="$q" --print-query \
--expect=ctrl-d,ctrl-b);
do
IFS=$'\n'; set -f
lines=($(<<< "$out"))
unset IFS; set +f
q="${lines[0]}"
k="${lines[1]}"
sha="${lines[-1]}"
sha="${sha%% *}"
[[ -z "$sha" ]] && continue
if [[ "$k" == 'ctrl-d' ]]; then
git diff $sha
elif [[ "$k" == 'ctrl-b' ]]; then
git stash branch "stash-$sha" $sha
break;
else
git -c color.ui=always stash show -p $sha | less -+F
fi
done
}
# Automatically cd after ranger closes
ranger_cd() {
tempfile="$(mktemp -t tmp.XXXXXX)"
ranger --choosedir="$tempfile" "${@:-$(pwd)}"
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
cd -- "$(cat "$tempfile")"
fi
rm -f -- "$tempfile"
}
# Open up man, OSX edition
# http://www.commandlinefu.com/commands/view/7581/rtfm-function#comment
rtfm() {
help $@ || man $@ || open "http://www.google.com/search?q=$@";
}
# Lazy load travis.rb
travis() {
source $HOME/.travis/travis.sh
unset -f travis
travis "$@"
}