-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers
72 lines (63 loc) · 2.74 KB
/
helpers
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
# to create a file of a given size: /usr/sbin/mkfile or /usr/bin/hdiutil
# ---------------------------------------
# e.g.: mkfile 10m 10MB.dat
# e.g.: hdiutil create -size 10m 10MB.dmg
# aliases
alias reload='. ~/.bash_profile'
alias ls='ls -G'
alias cp='cp -iv' # Preferred 'cp' implementation
alias mv='mv -iv' # Preferred 'mv' implementation
alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation
alias ll='ls -FGlAhp' # Preferred 'ls' implementation
alias less='less -FSRXc' # Preferred 'less' implementation
alias f='open -a Finder ./' # f: Opens current directory in MacOS Finder
alias which='type -all' # which: Find executables
alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths
alias myip='curl checkip.amazonaws.com' # myip: Public facing IP Address
mcd () { mkdir -pv "$1" && cd "$1"; } # mcd: Makes new Dir and jumps inside
trash () { command mv "$@" ~/.Trash ; } # trash: Moves a file to the MacOS trash
serve () { ruby -run -e httpd "$1" -p9090; }
# cleanupDS: Recursively delete .DS_Store files
alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"
# For git diff: strips leading "+" and "-"
function strip_diff_leading_symbols() {
color_code_regex="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K])"
# simplify the unified patch diff header
gsed -r "s/^($color_code_regex)diff --git .*$//g" | \
gsed -r "s/^($color_code_regex)index .*$/\n\1$(rule)/g" | \
gsed -r "s/^($color_code_regex)\+\+\+(.*)$/\1+++\5\n\1$(rule)\x1B\[m/g" |\
# actually strips the leading symbols
gsed -r "s/^($color_code_regex)[\+\-]/\1 /g"
}
# Print a horizontal rule
rule () {
printf "%$(tput cols)s\n"|tr " " "─"}}
}
# extract: 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 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# "dev" directory helper with case-insensitive sub-directory tab-completion :)
function dev() { cd "$HOME/Dev/$1"; }
complete -C ~/.bash/dev_completion -o filenames -o nospace dev
# Source bash-completion from Homebrew
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi