-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_aliases
More file actions
181 lines (170 loc) · 6.8 KB
/
bash_aliases
File metadata and controls
181 lines (170 loc) · 6.8 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
alias enw="emacs -nw"
alias ls="ls --color=auto"
alias ll="ls -l --color=auto"
alias lsn='stat -c "%a %n"'
alias kcern="kinit -f $USER@CERN.CH"
alias kfnal="kinit -f $USER@FNAL.GOV"
alias at3="ssh -Y at3.pic.es"
alias at301="ssh -Y at301.pic.es"
alias gp1='ssh -Y gpatlas1.ps.uci.edu'
alias gp2='ssh -Y gpatlas2.ps.uci.edu'
alias gp1hop='ssh -tCL 5906:localhost:5906 lxplus.cern.ch ssh -CL 5906:localhost:22 gpatlas1.ps.uci.edu'
alias gp2hop='ssh -tCL 5907:localhost:5906 lxplus.cern.ch ssh -CL 5907:localhost:22 gpatlas2.ps.uci.edu'
alias vproxy='voms-proxy-init -voms atlas -valid 144:00'
alias saq='setupATLAS --quiet'
alias dipp='$HOME/bin/dipp.py' # get it from https://raw.github.com/davidegerbaudo/python-scripts/master/various/dipp.py
alias psu='pgrep -u $USER | xargs ps -f -p'
alias reset-caps='setxkbmap -option' # for when caps-lock gets stuck; restart xmonad afterward
alias kscreen="pgrep -fl krenew -u ${USER} || AKLOG=/usr/bin/aklog krenew -b -t -- screen -D -m ; screen -r"
alias stripcolors='sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"'
alias trimwhitespace="sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'"
## ls with numeric permission, see http://stackoverflow.com/questions/1795976/can-the-unix-list-command-ls-output-numerical-chmod-permissions
# some problem with double quotes in alias...to be fixed
#lsn() {
# ls -l $* | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
# }
#
# cannot define an alias with arg; use a function instead
mktoday() {
local target_dir="/var/tmp/${USER}/`date +%F`" && [[ $# -gt 0 ]] && target_dir="/var/tmp/${USER}/${1}-`date +%F`" ;
echo "mkdir ${target_dir}"
mkdir -p ${target_dir}
}
# determine whether this is an interactive shell
# (from http://tldp.org/LDP/abs/html/intandnonint.html)
isthisshellinteractive() {
case $- in
*i*) # interactive shell
echo yes
;;
*) # non-interactive shell
echo no
;;
esac
}
# short for 'find base-location -name "*some-name*" -exec grep some-thing {}' \; -print
fgrepp() {
if [[ 2 -gt $# || $# -gt 3 ]]
then
echo "Usage: fgrep where [approxname] whattogrep"
else
local base_dir="${1}"
local name_pattern="*" && [[ $# -gt 2 ]] && name_pattern="*${2}*" ;
local word_pattern="${2}" && [[ $# -gt 2 ]] && word_pattern="${3}" ;
# echo "find ${base_dir} -type f -iname \"${name_pattern}\" -exec grep --color='auto' ${word_pattern} {} \; -print"
find ${base_dir} -type f -iname "${name_pattern}" -exec grep --color='auto' ${word_pattern} {} \; -print
fi
}
# handy stuff inspired from https://news.ycombinator.com/item?id=7981633
function lt() { ls -ltrsa "$@" | tail; }
function mkcd() { mkdir $1 && cd $1; }
function hgrep() { history | grep -v grep | grep "$@" -i --color=auto; }
function psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto; }
function fname() { find . -iname "*$@*"; } ## find something here with ~name
function remove_lines_from() { grep -F -x -v -f $2 $1; } ## removes lines from $1 if they appear in $2
alias sum="xargs | tr ' ' '+' | bc" ## Usage: echo 1 2 3 | sum
alias netlook='lsof -Pni'
alias eosquota="eos quota | grep -A 4 \"Quota Node: /eos/atlas/user/$\" | head -5"
# A simple function to jot down my notes while working.
# Example usage
# > ls -ltrh *foo # nice command, I see it works
# > jot working from `pwd`, this works # jot down a note to self
# > jot ls -ltrh *foo # and the command
function jot() {
: ${JOT_DEST:?"Need to set a valid JOT_DEST file; use jot-set."}
if [ ! -e ${JOT_DEST} ]
then
touch ${JOT_DEST}
fi
local TIMESTAMP=$(date +%F-%T)
echo "${TIMESTAMP} -- ${@}" >> ${JOT_DEST}
}
function jot-last() {
: ${JOT_DEST:?"Need to set a valid JOT_DEST file; use jot-set."}
tail -n 4 ${JOT_DEST}
}
function jot-set() {
# function to pick a file where we jot things down
# based on http://stackoverflow.com/questions/15807845/list-files-and-show-them-in-a-menu-with-bash
local JOT_DIR="${HOME}/.jot/"
if [ ! -d ${JOT_DIR} ]; then mkdir ${JOT_DIR}; fi
local PROMPT="Please select a file:"
local OPTIONS=( $(find ${JOT_DIR} -maxdepth 1 -type f -regex ".*\.\(org\|txt\)" -print0 | xargs -0) )
local OPT=""
PS3="$PROMPT "
select OPT in "${OPTIONS[@]}" "Quit" ; do
if (( REPLY == 1 + ${#OPTIONS[@]} )) ; then
exit
elif (( REPLY > 0 && REPLY <= ${#OPTIONS[@]} )) ; then
echo "You picked ${OPT} which is file ${REPLY}"
export JOT_DEST=${OPT}
break
else
echo "Invalid option. Try another one, or 'touch' ${JOT_DIR}/file if you want a new one."
fi
done
# ls -ld ${OPT} # just for dbg
}
# git aliases
alias gad='git add'
alias gadp='git add -p'
alias gpu='git push'
alias glg='git log'
alias glp='git log --pretty=format:"%h - %an, %ad : %s"'
alias glt='git log --oneline --graph --decorate --all'
alias glts='git log --graph --simplify-by-decoration --pretty=format:%d --all'
alias gst='git status'
alias gdf='git diff'
alias gdfc='git diff --cached'
alias gci='git commit'
alias gcm='git commit -m'
alias gcma='git commit -am'
alias gbr='git branch'
alias gco='git checkout'
alias gra='git remote add'
alias grr='git remote rm'
alias gpl='git pull'
alias gcl='git clone'
alias gtan='git tag -a' # create annotated tag
alias gtal='git tag -n1' # list tags with annotations
function git-pull-attach-to-issue() {
# create a pull request attaching a branch to an existing issue
# see http://stackoverflow.com/questions/4528869/how-do-you-attach-a-new-pull-request-to-an-existing-issue-on-github
local username
local repository
local from_branch
local to_branch
local issue_number
read -r -p 'username : ' username
read -r -p 'repository : ' repository
read -r -p 'from_branch : ' from_branch
read -r -p 'to_branch : ' to_branch
read -r -p 'issue_number : ' issue_number
local cmd="curl"
cmd="${cmd} --user \"${username}\""
cmd="${cmd} --request POST"
cmd="${cmd} --data '{\"issue\": \"${issue_number}\", \"head\": \"${username}:${from_branch}\", \"base\": \"${to_branch}\"}'"
cmd="${cmd} https://api.github.com/repos/${username}/${repository}/pulls"
echo ${cmd}
}
# svn aliases
alias svs='svn status'
alias svi='svn info'
alias svd='svn diff --diff-cmd colordiff'
alias svdiw='svn diff -x --ignore-all-space'
alias svu='svn update'
alias svc='svn commit'
alias svcm='svn commit -m'
# mount remote disks
function lxmount() {
# run without (mount) or with '-u' (unmount)
if [[ 0 -eq $# ]]
then
sshfs gerbaudo@lxplus.cern.ch:/afs/cern.ch/user/g/gerbaudo /home/gerbaudo/fuse-cern
else
fusermount -u /home/gerbaudo/fuse-cern
fi
}
function lp32() {
cat $* | ssh lxplus.cern.ch lpr -P 32-SB02-CANON
}