Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

bashrc

View gist:2035990
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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
#!/bin/bash
# ~/.bashrc
#
#
# shosei
 
# Shell Init
[[ $PATH = *local/bin* ]] || PATH=$PATH:/usr/local/bin
[[ $- = *i* ]] || return
source bashlib
 
# by OS
if [[ $MACHTYPE = *darwin* ]]; then
# MAC ----------------#
 
qview() {
files=("$@"); i=0
while true; do
file=${files[i]}
qlmanage -p "$file" & pid=$!
read -sn1 key
kill $pid || key=q
wait $pid
 
case $key in
q) return ;;
p) let i-- ;;
*) let i++ ;;
esac
 
(( i < ${#files[@]} )) || break
(( i < 0 )) && i=0
done
} 2>/dev/null
 
qthumb() {
qlmanage -t "$@" & pid=$!
read -sn1
 
kill $pid; wait $pid
} 2>/dev/null
fi
 
 
 
 
# Applications
alias cal="cal -m -3"
alias git="nice git"
alias gsh="git stash"
alias gst="git status --short --branch"
alias gsu="git submodule update --recursive --merge"
alias gdf="git diff"
alias gdt="git difftool"
alias glo="git log"
alias gps="git push"
alias gpl="git pull"
alias gco="git checkout"
alias gci="git commit"
alias gad="git add"
alias grm="git rm"
alias gmv="git mv"
alias gtg="git tag"
alias gbr="git branch"
alias gs="git svn"
 
 
 
 
 
# System
s() {
fc -s "$1=$2"
}
exists wdiff && \
alias wdiff="wdiff -a"
exists less && \
alias more="less" || \
alias less="more"
alias kbg='bg; kill $!; fg'
exists ltrace && \
alias trace="ltrace -C -f -n 4 -S"
exists pcregrep && \
alias pcregrep="pcregrep --color=auto"
alias grep="grep -I --color=auto"
alias egrep="grep -E"
alias fgrep="grep -F"
alias pg="pgrep -l"
if exists pstree; then
p() {
if pstree -A >/dev/null 2>&1; then
pstree -Aahlpu
else
[[ -t 1 ]] \
&& pstree -w -g2 \
|| pstree -w -g1 | recode -fg IBM850..UTF8
fi
}
else
if ps auxf >/dev/null 2>&1; then
p() { ps auxf; }
else
p() { ps aux; }
fi
fi
alias pp="p | less"
top -u -h >/dev/null 2>&1 && \
alias top="top -S -u -stats pid,ppid,user,cpu,time,threads,state,rprvt,vprvt,faults,command"
 
# fink.env
test -r /sw/bin/init.sh && . /sw/bin/init.sh
 
 
 
 
# applications.startup
exists todo && todo
mysqlstart() {
sudo bash -c 'nice /opt/local/bin/mysqld_safe5 "$@" &' -- "$@"
}
mysqlstop() {
/opt/local/bin/mysqladmin5 -u root -p shutdown "$@"
}
 
 
 
 
# Filesystem
alias noproxy="http_proxy= HTTP_PROXY= https_proxy= HTTPS_PROXY= ftp_proxy= FTP_PROXY="
alias rs="nice rsync --archive --no-owner --sparse --hard-links --partial --progress"
alias rsz="rs --compress-level=9 --skip-compress=gz/zip/z/rpm/deb/iso/bz2/t[gb]z/7z/mp[34]/mov/avi/ogg/jpg/jpeg/rar/gif/png/dat"
alias port="sudo nice port"
alias mvn="nice mvn"
alias cp="nice cp -v"
alias mv="nice mv -v"
alias tree="tree -F --dirsfirst"
if ls --color >/dev/null 2>/dev/null; then
alias ls="ls -bFk --color=auto"
else
alias ls="ls -bFkG"
fi
alias ll="ls -lh"
alias l=" ll -a"
alias df="nice df -h"
 
 
 
 
 
# Network
alias n="netstat -np tcp"
alias mtr="mtr -t"
alias nmap="nmap -v -v -T5"
alias nmapp="nmap -P0 -A --osscan_limit"
alias pktstat="sudo pktstat -tBFT"
 
 
 
 
# shell history
shopt -s histappend
HISTCONTROL=ignoreboth
HISTSIZE=
HISTFILE=~/.bash.log
HISTFILESIZE=
HISTTIMEFORMAT='%F %T%t'
 
 
 
# theme.shell
shopt -s extglob
shopt -qs globstar
shopt -qs checkwinsize
shopt -qs hostcomplete
shopt -qs no_empty_cmd_completion
stty stop undef
stty -echoctl
 
#[[ -f /etc/bash_completion ]] && \
# source /etc/bash_completion
[[ -f ~/.share/git-svn-extensions/source.sh ]] && \
source ~/.share/git-svn-extensions/source.sh
 
 
 
# xterm/rxvt/screen.Terminal title
case "$TERM" in
?term*|rxvt*|gnome*|interix)
PROMPT_COMMAND='history -a; echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"' ;;
screen*)
PROMPT_COMMAND='history -a; echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"' ;;
esac
 
 
 
 
# prompt.PS1
PS1='\h\[$blue\] $(git-repo-status)\W \[$red\]${?/#0/\[$green\]}\$\[$reset\] '
if (( EUID )); then
PS1='\[$reset$bold$green\]\u@'$PS1
else
PS1='\[$reset$bold$red\]'$PS1
fi
forcePS1ToFront() {
origExitCode=$?
read r c < <(cloc)
(( c > 1 )) && printf '\n' >&2
return $origExitCode
}
 
# Force the prompt on a new line if the cursor isn't at the beginning of the line.
# PS1='$(forcePS1ToFront)'$PS1
 
# PS1='\[$reset$bold$green\]\u@\h\[$blue\] \W \[$green\]$(: "${?#0}"; printf "\[%s\]" "${_:+$save$red\r$_ $load}")\$\[$reset\] '
 
 
 
 
# shell.colors
if [[ -f /etc/DIR_COLORS.env ]]
then source "/etc/DIR_COLORS.env"
elif [[ -f /etc/DIR_COLORS ]] && exists dircolors
then eval "$(dircolors -b "/etc/DIR_COLORS")"
fi
if [[ -f ~/.dir_colors.env ]]
then source ~/.dir_colors.env
elif [[ -f ~/.dir_colors ]] && exists dircolors
then eval "$(dircolors -b ~/.dir_colors)"
fi
 
 
 
# X Resources.
#[ "$DISPLAY" -a -f "$HOME/.Xdefaults" ] && \
# exists xrdb && xrdb "$HOME/.Xdefaults"
 
 
 
 
# completion.shell
complete_getpw() {
local successes candidates
source ~/.getpw
for url in "${!urls[@]}"; do
[[ $url = $2* ]] || continue
 
successes=${urls["$url"]}
if (( successes )); then
COMPREPLY+=("$url")
fi
done
}
complete_pw() {
local successes candidates
source ~/.pw.conf
for host in "${!uses[@]}"; do
[[ $host = $2* ]] || continue
 
use=${uses["$host"]}
if (( use > 0 )); then
COMPREPLY+=("$host")
fi
done
}
complete -F complete_getpw getpw
complete -F complete_pw pw
complete -A command sudo
 
 
 
 
# functions
i() {
bash --rcfile <(printf '%s\n' "$(<~/.bashrc)" "HISTFILE='$HISTFILE.i'" "PS1='\[$yellow\]~\[$reset\]$PS1'" "cd; clear"); clear
}
d() {
if exists colordiff; then
colordiff -ur "$@"
elif exists diff; then
diff -ur "$@"
elif exists comm; then
comm -3 "$1" "$2"
fi | less
}
# f pattern [find-args]
f() {
local root pattern=$1; shift
 
find "${@:-.}" -iname "*$pattern*"
}
rerun() {
local h history histories dialogMenu=() startIndex
# Load in history entries (ignoring the last)
IFS=$'\n' read -r -d '' -a histories < <(history | tail -n "${1:-10}")
unset histories[${#histories[@]}-1]
 
# Build a dialog(1) menu and show it to ask for the starting index.
for h in "${!histories[@]}"; do dialogMenu+=( "$h" "${histories[h]}" ); done
startIndex=$(dialog --stdout --menu "Bash History" 0 0 0 "${dialogMenu[@]}")
 
# Run all history commands starting from the starting index.
for history in "${histories[@]:startIndex}"; do
eval "${history#*$'\t'}" || break
done
}
sw() {
local bak="$1~"
while [[ -e $bak ]]
do bak+='~'; done
mv -v "$1" "$bak"
mv -v "$2" "$1"
mv -v "$bak" "$2"
}
ppg() {
pat=$1; shift
p | grep -i "$@" "$pat"
}
cwatch() {
while sleep .5; do
o="$("$@")"
clear && echo "$o"
done
}
mvns() {
export PATH=/usr/local/share/soylatte16-amd64-1.0.3/bin:${PATH}
export JAVA_HOME=/usr/local/share/soylatte16-amd64-1.0.3
 
mvn "$@"
}
mvnroot() {
local p=$PWD c=${1:-1}
until p=${p%/*}; [[ -e "$p/pom.xml" ]] && (( --c <= 0 )); do :; done
 
echo "${p}${red}${PWD#$p}${reset}"
cd "$p"
}
gf() {
git-forest -a --sha "${@:---all}" | less
}
gd() {
git describe --always --dirty
}
gdm() {
emit "GIT Daemon starting with base path: $(shorten "$PWD")"
git daemon --base-path=. "$@" &
}
git-redo-move() {
(( $# == 2 )) || { emit -r "Expected two parameters; [source] [destination]."; return; }
[[ -e $2 ]] || { emit -r "$2 doesn't exist, can't redo ."; return; }
[[ ! -e $1 ]] || { emit -r "$1 exists, don't want to overwrite, redo move aborted."; return; }
mkdir -p "${1%/*}" && \mv "$2" "$1" && git mv "$1" "$2" && rmdir -p "${1%/*}"
}
git-repo-status() {
local exit=$? cwd=$PWD repo= tag
 
while [[ $cwd ]]; do
[[ -d $cwd/.git ]] && { repo=git; break; }
 
cwd=${cwd%/*}
done
 
case $repo in
git)
if ! tag=$(git describe --tags --exact-match 2>&-); then
tag=$(git describe --tags 2>&-)
tag=${tag%-*} # Chop off hash.
fi
printf '[%s%s%s] \n' "${cwd##*/}" "${tag:+:}" "$tag"
;;
esac
 
return $exit
}
portget() {
(( $# )) || { emit -r "$0 [revision] [category/portname]"; return; }
 
[[ -e "${2#*/}" ]] && { ask -Ny! 'Target exists, delete?' && rm -rf "${2#*/}" || return; }
svn co -r "$1" http://svn.macports.org/repository/macports/trunk/dports/"$2"
cd "${2#*/}"
}
 
 
 
 
# functions.networking
exists lft && \
lft() {
sudo lft -S "$@" | tail -n +3 | column -t
}
svnup() {
local cRev=$(svn info | awk '/^Revision:/ { print $2 }')
[[ $cRev ]] || { emit -r "Not in a repository."; return 1; }
 
emit "Looking for updates to r$cRev"
svn up
 
local nRev=$(svn info | awk '/^Revision:/ { print $2 }')
[[ $nRev = $cRev ]] && {
emit "Nothing to update."
return
}
 
echo
emit "Changelog $cRev -> $nRev:"
svn log -r$((cRev+1)):$nRev | while IFS= read -r line; do
[[ $line ]] || continue
 
[[ $line != *[^-]* ]] && { begin=1; continue; }
if (( begin )); then
read rev _ user _ d t _ <<< "$line"
echo
echo "$bold$green$user$reset - r$bold${rev#r}$reset: "$'\t'"($bold$d$reset - $bold$t$reset)"
begin=0
else
[[ $line = *:* ]] \
&& echo $'\t'"$reset- $bold$blue${line%%:*}$reset:${line#*:}" \
|| echo $'\t'"$reset- $line"
fi
done
 
echo
emit "To view the code diff of these updates; execute: svn diff -r$cRev:$nRev $(quote "$@")"
}
 
 
 
# functions.filesystem
cc() {
[[ $@ =~ ^\ *(.*)\ +([^\ ]+)\ *$ ]] && \
tar -Sc ${BASH_REMATCH[1]} | \
tar --preserve -xvC ${BASH_REMATCH[2]}
}
 
 
 
 
 
# functions.eval
calc() { python -c "import math; print $*"; }
c() {
local out="${TMPDIR:-/tmp}/c.$$" strict=1
trap 'rm -f "$out"' RETURN
 
[[ $1 = -l ]] && { strict=; shift; }
local code="
#include <unistd.h>
#include <stdio.h>
#include <math.h>
int main(int argc, const char* argv[]) {
$1;
return 0;
}"
shift
 
if ! gcc -x c -o "$out" -Wall ${strict:+-Werror} - <<< "$code"; then
emit -r "Compilation failed:"
cat -n <<< "$code"
return 255
else
chmod +x "$out" && "$out" "$@"
fi
}
 
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.