UNPKG

9.07 kBapplication/x-shView Raw
1
2# if ! type "trash" > /dev/null; then
3# echo "Instaling dependency for moving files to trash."
4# npm install trash-cli -g
5# fi
6
7# some chrome versions require this for you to enter on a meeting
8alias fixcamera="sudo killall VDCAssistant"
9# your IP in the local network
10alias ipin="ipconfig getifaddr en0"
11# your IP seen from outside
12alias ipout='dig +short myip.opendns.com @resolver1.opendns.com'
13# more information about your ip
14alias ip="echo -e Internal IP Address: ; ipconfig getifaddr en0; echo -e Public facing IP Address: ; curl ipecho.net/plain ; echo ;"
15alias aliases='alias'
16alias ..='cd ..'
17alias cd..='cd ..'
18alias .2="cd ../../"
19alias .3="cd ../../../"
20alias .4="cd ../../../../"
21alias .5="cd ../../../../../"
22alias .6="cd ../../../../../../"
23alias .7="cd ../../../../../../../"
24alias ll='ls -FGlAhp'
25alias ls='ls -FA'
26alias ~="cd ~"
27alias root="cd /"
28alias www="cd /var/www/"
29alias commit="git commit -a"
30alias commitAll="git add -A; git commit -a"
31alias gitlog="git log --graph --decorate --oneline"
32alias gittree="git log --graph --decorate --oneline --all"
33alias checkout="git checkout"
34
35function bold () {
36 echo "$(tput bold)$@$(tput sgr0)"
37}
38alias bold="bold"
39
40alias push="git push origin"
41alias pull="git pull origin"
42alias exit="exit && echo 0 > ~/.uis"
43alias line="printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -"
44alias doubleline="printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' ="
45alias sizes="sudo du -cxhd 1"
46alias flushDNS='dscacheutil -flushcache'
47alias DSFiles_removal="find . -type f -name '*.DS_Store' -ls -delete"
48alias hosts_edit='sudo vim /etc/hosts'
49alias reloadprofiler='source ~/.bash_profile'
50alias reload="exec ${SHELL} -l"
51# alias reload="tset 2>/dev/null || reset"
52alias h='history'
53alias today='date +"%d-%m-%Y"'
54alias now='date +"%T"'
55alias ports='netstat -tulanp'
56alias lsd='ll | grep "^d" --colors=never' # ls for only directories
57alias lsf='ll | grep "^[^d]" --color=no' # ls for only files
58alias grep='grep --color=auto'
59alias fgrep='fgrep --color=auto'
60alias egrep='egrep --color=auto'
61
62alias desktop='cd ~/Desktop'
63alias desk='cd ~/Desktop'
64alias d='cd ~/Documents'
65alias docs='cd ~/Documents'
66alias documents='cd ~/Documents'
67alias downloads='cd ~/Downloads'
68alias down='cd ~/Downloads'
69alias amionline="ping www.google.com -t 1 2>/dev/null >/dev/null && echo \"Yes\" || echo \"No\""
70alias amioffline="ping www.google.com -t 1 2>/dev/null >/dev/null && echo \"No\" || echo \"Yes\""
71
72alias ifactive="ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'"
73alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
74command -v md5sum > /dev/null || alias md5sum="md5"
75command -v sha1sum > /dev/null || alias sha1sum="shasum"
76
77function dog () {
78 cat $@ | less -FRNX
79}
80
81# Show/hide hidden files in Finder
82alias show-hidden-files="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
83alias hide-hidden-files="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"
84
85# Tip imported from Mathias Bynens' dotfiles
86# https://github.com/mathiasbynens/dotfiles/blob/master/.aliases
87# Print each PATH entry on a separate line
88alias path='echo -e ${PATH//:/\\n}'
89# Lock the screen (when going AFK)
90alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
91# Kill all the tabs in Chrome to free up memory
92# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
93alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"
94# Hide/show all desktop icons (useful when presenting)
95alias hide-desktop-icons="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
96alias show-desktop-icons="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"
97#Requests
98for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
99 alias "${method}"="lwp-request -m '${method}'"
100done
101# Use Git’s colored diff when available
102hash git &>/dev/null;
103if [ $? -eq 0 ]; then
104 function diff() {
105 git diff --no-index --color-words "$@";
106 }
107fi;
108# `hierarchy` is a shorthand for `tree` with hidden files and color enabled, ignoring
109# the `.git` directory, listing directories first. The output gets piped into
110# `less` with options to preserve color and line numbers, unless the output is
111# small enough for one screen.
112function hierarchy() {
113 tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
114}
115
116# Determine size of a file or total size of a directory
117function sizeof() {
118 if du -b /dev/null > /dev/null 2>&1; then
119 local arg=-sbh;
120 else
121 local arg=-sh;
122 fi
123 if [[ -n "$@" ]]; then
124 du $arg -- "$@";
125 else
126 du $arg .[^.]* ./*;
127 fi;
128}
129# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
130function targz() {
131 local tmpFile="${@%/}.tar";
132 tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1;
133
134 size=$(
135 stat -f"%z" "${tmpFile}" 2> /dev/null; # macOS `stat`
136 stat -c"%s" "${tmpFile}" 2> /dev/null; # GNU `stat`
137 );
138
139 local cmd="";
140 if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
141 # the .tar file is smaller than 50 MB and Zopfli is available; use it
142 cmd="zopfli";
143 else
144 if hash pigz 2> /dev/null; then
145 cmd="pigz";
146 else
147 cmd="gzip";
148 fi;
149 fi;
150
151 echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…";
152 "${cmd}" -v "${tmpFile}" || return 1;
153 [ -f "${tmpFile}" ] && rm "${tmpFile}";
154
155 zippedSize=$(
156 stat -f"%z" "${tmpFile}.gz" 2> /dev/null; # macOS `stat`
157 stat -c"%s" "${tmpFile}.gz" 2> /dev/null; # GNU `stat`
158 );
159
160 echo "${tmpFile}.gz ($((zippedSize / 1000)) kB) created successfully.";
161}
162
163# other useful aliases, focused on safety
164alias chown='chown --preserve-root'
165# alias chmod='chmod --preserve-root'
166alias chgrp='chgrp --preserve-root'
167
168alias rm="/bin/rm -i"
169
170# extract: Extract most know archives with one command
171# ---------------------------------------------------------
172 extract () {
173 if [ -f $1 ] ; then
174 case $1 in
175 *.tar.bz2) tar xjf $1 ;;
176 *.tar.gz) tar xzf $1 ;;
177 *.bz2) bunzip2 $1 ;;
178 *.rar) unrar e $1 ;;
179 *.gz) gunzip $1 ;;
180 *.tar) tar xf $1 ;;
181 *.tbz2) tar xjf $1 ;;
182 *.tgz) tar xzf $1 ;;
183 *.zip) unzip $1 ;;
184 *.Z) uncompress $1 ;;
185 *.7z) 7z x $1 ;;
186 *) echo "'$1' cannot be extracted via extract()" ;;
187 esac
188 else
189 echo "'$1' is not a valid file"
190 fi
191 }
192
193# findPid: find out the pid of a specified process
194# -----------------------------------------------------
195# Note that the command name can be specified via a regex
196# E.g. findPid '/d$/' finds pids of all processes with names ending in 'd'
197# Without the 'sudo' it will only find processes of the current user
198# -----------------------------------------------------
199 pid () { lsof -t -c "$@" ; }
200
201# ii: display useful host related informaton
202# -------------------------------------------------------------------
203 about() {
204 local U
205 U= `whoami`
206 echo -e "\nYou are logged on ${RED}$HOST as $IM"
207 echo -e "\nAdditionnal information:$NC " ; uname -a
208 echo -e "\n${RED}Users logged on:$NC " ; w -h
209 echo -e "\n${RED}Current date :$NC " ; date
210 echo -e "\n${RED}Machine stats :$NC " ; uptime
211 echo -e "\n${RED}Current network location :$NC " ; scselect
212 echo -e "\n${RED}Local IP Address :$NC " ; ipin
213 echo -e "\n${RED}Public facing IP Address :$NC " ; ipout
214 #echo -e "\n${RED}DNS Configuration:$NC " ; scutil --dns
215 echo
216 }
217
218#!/usr/bin/env bash
219# Usage: goo.gl [URL]
220#
221# Shorten a URL using the Google URL Shortener service (http://goo.gl).
222# (imported from https://gist.github.com/wafflesnatcha/3694648)
223googl() {
224 [[ ! $1 ]] && { echo -e "Usage: goo.gl [URL]\n\nShorten a URL using the Google URL Shortener service (http://goo.gl)."; return; }
225 curl -qsSL -m10 --connect-timeout 10 \
226 'https://www.googleapis.com/urlshortener/v1/url' \
227 -H 'Content-Type: application/json' \
228 -d '{"longUrl":"'${1//\"/\\\"}'"}' |
229 perl -ne 'if(m/^\s*"id":\s*"(.*)",?$/i) { print $1 }'
230}
231
232# shrink URLS using goo.gl service
233alias short="googl"
234
235# back and forward with cd
236export BACK_HISTORY=""
237export FORWARD_HISTORY=""
238
239function cd {
240 BACK_HISTORY=$PWD:$BACK_HISTORY
241 FORWARD_HISTORY=""
242 builtin cd "$@"
243}
244
245function back {
246 DIR=${BACK_HISTORY%%:*}
247 if [[ -d "$DIR" ]]
248 then
249 BACK_HISTORY=${BACK_HISTORY#*:}
250 FORWARD_HISTORY=$PWD:$FORWARD_HISTORY
251 builtin cd "$DIR"
252 fi
253}
254
255function forward {
256 DIR=${FORWARD_HISTORY%%:*}
257 if [[ -d "$DIR" ]]
258 then
259 FORWARD_HISTORY=${FORWARD_HISTORY#*:}
260 BACK_HISTORY=$PWD:$BACK_HISTORY
261 builtin cd "$DIR"
262 fi
263}