forked from jonkan/.dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.functions
executable file
·98 lines (88 loc) · 2.69 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
92
93
94
95
96
97
98
# Git commit random message
gcmrand() {
git commit -m"`curl -s http://whatthecommit.com/index.txt`"
}
gcamrand() {
git add '.'
gcmrand
}
# List all branches which are missing upstream branch ('gone') and prompts if it should remove them or not. (not force delete!)
git_rm_all_gone_branches() {
git fetch -p > /dev/null 2>&1
git branch -vv | grep -v '^*' | grep ": gone]" | awk '{ print $1 " " $2 " " $3 " " $4 }'
echo "Do you want to delete the branches above?"
select yn in "Yes" "Yes, force-delete" "No"; do
case $yn in
Yes ) git branch -vv | grep ": gone]" | awk '{print $1}' | xargs -n 1 git branch -d; break;;
"Yes, force-delete" ) git branch -vv | grep ": gone]" | awk '{print $1}' | xargs -n 1 git branch -D; break;;
No ) return;;
esac
done
}
# Extract most know archives with one command
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*.sfx) unrar e $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Make and cd into directory
function mkd() {
mkdir -p "$1" && cd "$1";
}
# cd into whatever is the forefront Finder window.
cdf() { # short for cdfinder
cd "`osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)'`"
}
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
function targz() {
local tmpFile="${@%/}.tar"
tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1
size=$(
stat -f"%z" "${tmpFile}" 2> /dev/null; # OS X `stat`
stat -c"%s" "${tmpFile}" 2> /dev/null # GNU `stat`
)
local cmd=""
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
# the .tar file is smaller than 50 MB and Zopfli is available; use it
cmd="zopfli"
else
if hash pigz 2> /dev/null; then
cmd="pigz"
else
cmd="gzip"
fi
fi
echo "Compressing .tar using \`${cmd}\`…"
"${cmd}" -v "${tmpFile}" || return 1
[ -f "${tmpFile}" ] && rm "${tmpFile}"
echo "${tmpFile}.gz created successfully."
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh
else
local arg=-sh
fi
if [[ -n "$@" ]]; then
du $arg -- "$@"
else
du $arg .[^.]* *
fi
}