forked from colonelpanic/dotfiles
Add iterm settings, tweak bootstrap, bump eamcs pointer.
Fix web_start. Add remote_clipboard server stuff. Bump .emacs.d pointer and add remote_os_copy alias. Way better get_cols Made git sui git suir move to same sha as yelp branch for .emacs.d Bump emacs pointer. simplified default code for remote_clipboard. Remove unused functions from .functions. Added things from yelp branch. yelpify Added field separator to get_cols. Lots of refactoring. Added .lib directory. Moved dotfiles that get symlinked to ~ into their own directory. Remove some vim configuration. Remove oh-my-zsh.
This commit is contained in:
52
dotfiles/lib/shellrc/aliases.sh
Normal file
52
dotfiles/lib/shellrc/aliases.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
alias script_abspath='$(dirname "${BASH_SOURCE}" | xargs "${readlink_command}" -f)'
|
||||
|
||||
alias emacs="emacsclient -t"
|
||||
alias readlink="greadlink"
|
||||
|
||||
alias sudo='sudo '
|
||||
|
||||
# IP addresses
|
||||
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
|
||||
alias localip="ifconfig getifaddr en1"
|
||||
|
||||
alias whois="whois -h whois-servers.net"
|
||||
|
||||
# Clean up LaunchServices to remove duplicates in the “Open With” menu
|
||||
alias lscleanup="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
|
||||
|
||||
# View HTTP traffic
|
||||
alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
|
||||
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
|
||||
|
||||
# Canonical hex dump; some systems have this symlinked
|
||||
command -v hd > /dev/null || alias hd="hexdump -C"
|
||||
|
||||
# OS X has no `md5sum`, so use `md5` as a fallback
|
||||
command -v md5sum > /dev/null || alias md5sum="md5"
|
||||
|
||||
# OS X has no `sha1sum`, so use `shasum` as a fallback
|
||||
command -v sha1sum > /dev/null || alias sha1sum="shasum"
|
||||
|
||||
# URL-encode strings
|
||||
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
|
||||
|
||||
# Merge PDF files
|
||||
# Usage: `mergepdf -o output.pdf input{1,2,3}.pdf`
|
||||
alias mergepdf='/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py'
|
||||
|
||||
# Disable Spotlight
|
||||
alias spotoff="sudo mdutil -a -i off"
|
||||
# Enable Spotlight
|
||||
alias spoton="sudo mdutil -a -i on"
|
||||
|
||||
# One of @janmoesen’s ProTip™s
|
||||
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
|
||||
alias "$method"="lwp-request -m '$method'"
|
||||
done
|
||||
|
||||
alias stfu="osascript -e 'set volume output muted true'"
|
||||
alias pumpitup="osascript -e 'set volume 7'"
|
||||
|
||||
alias tmux="tmux -2"
|
||||
alias remote_os_copy='linux_nc_paste_to_remote_clipboard'
|
||||
alias timestamp='date +%s'
|
21
dotfiles/lib/shellrc/exports.sh
Normal file
21
dotfiles/lib/shellrc/exports.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
# Make emacs the default editor.
|
||||
export EDITOR="emacsclient"
|
||||
export ALTERNATE_EDITOR=""
|
||||
export VISUAL="emacsclient"
|
||||
|
||||
# Larger bash history (allow 32³ entries; default is 500)
|
||||
export HISTSIZE=32768
|
||||
export HISTFILESIZE=$HISTSIZE
|
||||
export HISTCONTROL=ignoredups
|
||||
# Make some commands not show up in history
|
||||
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"
|
||||
|
||||
# Prefer US English and use UTF-8
|
||||
export LANG="en_US"
|
||||
export LC_ALL="en_US.UTF-8"
|
||||
|
||||
# Highlight section titles in manual pages
|
||||
export LESS_TERMCAP_md="$ORANGE"
|
||||
|
||||
# Don’t clear the screen after quitting a manual page
|
||||
export MANPAGER="less -X"
|
66
dotfiles/lib/shellrc/functions.sh
Normal file
66
dotfiles/lib/shellrc/functions.sh
Normal file
@@ -0,0 +1,66 @@
|
||||
function parse_git_branch() {
|
||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
|
||||
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
|
||||
echo ${ref#refs/heads/}
|
||||
}
|
||||
|
||||
function current_shell() {
|
||||
ps -p $$ | tail -1 | awk '{print $NF}' | xargs which | xargs readlink -f
|
||||
}
|
||||
|
||||
function is_zsh() {
|
||||
test -n "$(current_shell | grep -o zsh)"
|
||||
}
|
||||
|
||||
function get_cols() {
|
||||
FS=' '
|
||||
while getopts "F:" OPTCHAR; do
|
||||
case $OPTCHAR in
|
||||
F)
|
||||
FS=$OPTARG
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
awk -f "$HOME/.lib/get_cols.awk" -v "cols=$*" -v "FS=$FS"
|
||||
}
|
||||
|
||||
function find_all_ssh_agent_sockets() {
|
||||
find /tmp -type s -name agent.\* 2> /dev/null | grep '/tmp/ssh-.*/agent.*'
|
||||
}
|
||||
|
||||
function set_ssh_agent_socket() {
|
||||
export SSH_AUTH_SOCK=$(find_all_ssh_agent_sockets | tail -n 1 | awk -F: '{print $1}')
|
||||
}
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
# Start an HTTP server from a directory, optionally specifying the port
|
||||
function server() {
|
||||
local port="${1:-8000}"
|
||||
sleep 1 && open "http://localhost:${port}/" &
|
||||
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
|
||||
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
|
||||
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
|
||||
}
|
||||
|
||||
# All the dig info
|
||||
function digga() {
|
||||
dig +nocmd "$1" any +multiline +noall +answer
|
||||
}
|
||||
|
||||
function shell_stats() {
|
||||
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
|
||||
}
|
10
dotfiles/lib/shellrc/path.sh
Normal file
10
dotfiles/lib/shellrc/path.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
function add_to_front_of_path {
|
||||
export PATH=$@:`echo $PATH | sed "s|:*$@||g" | sed "s|^:||"`
|
||||
}
|
||||
|
||||
function add_to_back_of_path {
|
||||
export PATH=`echo $PATH | sed "s|:*$@||g" | sed "s|^:||"`:$@
|
||||
}
|
||||
|
||||
add_to_back_of_path "$HOME/.local/lib/python2.6/site-packages"
|
||||
add_to_front_of_path "/usr/local/bin"
|
0
dotfiles/lib/shellrc/prompt.sh
Normal file
0
dotfiles/lib/shellrc/prompt.sh
Normal file
20
dotfiles/lib/shellrc/remote_clipboard.sh
Normal file
20
dotfiles/lib/shellrc/remote_clipboard.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
REMOTE_CLIPBOARD_PORT='1234'
|
||||
|
||||
function remote_clipboard_server() {
|
||||
while [ 1 ]
|
||||
do
|
||||
netcat -l -p ${1-$REMOTE_CLIPBOARD_PORT} -e "pbcopy"
|
||||
done
|
||||
}
|
||||
|
||||
function remote_clipboard_server_daemon() {
|
||||
daemonize `which reattach-to-user-namespace` -l $SHELL -c "source ~/.zshrc; remote_clipboard_server"
|
||||
}
|
||||
|
||||
function linux_nc_paste_to_remote_clipboard() {
|
||||
nc localhost ${1-$REMOTE_CLIPBOARD_PORT} -q 0
|
||||
}
|
||||
|
||||
function osx_nc_paste_to_remote_clipboard() {
|
||||
nc localhost ${1-$REMOTE_CLIPBOARD_PORT} -D
|
||||
}
|
87
dotfiles/lib/shellrc/yelp.sh
Normal file
87
dotfiles/lib/shellrc/yelp.sh
Normal file
@@ -0,0 +1,87 @@
|
||||
alias i="ipython tools/interactive.py"
|
||||
alias apperror="tools/scribereader -e prod -f apperror | tools/pretty_error_log"
|
||||
alias environ=". ~/.pgconf-$USER/environ.sh"
|
||||
alias ym="cd ~/pg/yelp-main"
|
||||
alias live="cd /nail/live/yelp"
|
||||
alias sb="sandbox -vv --minimal"
|
||||
|
||||
function fix_environment_script() {
|
||||
sed -i 's/export YELP_CONFIG:yelp_conn:replication_delay_params.*$//' $YELP_SANDBOX_ROOT/environment.sh
|
||||
}
|
||||
|
||||
function get_sandbox_identifier() {
|
||||
echo $YELP_SANDBOX_ROOT | gawk 'match($0, /pgconf-.*-(.*)/, matched) {print matched[1]}'
|
||||
}
|
||||
|
||||
function is_proddb() {
|
||||
python 2>/dev/null - <<END
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
|
||||
def is_proddb_from_topology_info(topology_info):
|
||||
for cluster_info in topology_info['topology']:
|
||||
if cluster_info['cluster'] == 'primary':
|
||||
return cluster_info['entries'][0]['host'] != '127.0.0.1'
|
||||
|
||||
def is_proddb_from_topology_filename(topology_filename):
|
||||
with open(topology_filename) as topology_file:
|
||||
return is_proddb_from_topology_info(yaml.load(topology_file))
|
||||
|
||||
def is_proddb():
|
||||
try:
|
||||
topology_filename = os.environ.get('TOPOLOGY_FILE')
|
||||
if topology_filename:
|
||||
return is_proddb_from_topology_filename(topology_filename)
|
||||
return False
|
||||
except:
|
||||
pass
|
||||
|
||||
sys.exit(0 if is_proddb() else 1)
|
||||
END
|
||||
}
|
||||
|
||||
function sandbox_prompt_info() {
|
||||
local sandbox_string=''
|
||||
if is_proddb
|
||||
then
|
||||
sandbox_string="proddb "
|
||||
fi
|
||||
if [ "$YELP_IN_SANDBOX" ];
|
||||
then
|
||||
sandbox_string=$sandbox_string"sandbox-$(get_sandbox_identifier)"
|
||||
else
|
||||
sandbox_string="no sandbox"
|
||||
fi
|
||||
echo $sandbox_string
|
||||
}
|
||||
|
||||
function bash_sandbox_color() {
|
||||
if [ $YELP_IN_SANDBOX ]
|
||||
then
|
||||
sandbox_color='\e[0;33m'
|
||||
else
|
||||
sandbox_color='\e[0;31m'
|
||||
fi
|
||||
}
|
||||
|
||||
function zsh_sandbox_color() {
|
||||
if [ $YELP_IN_SANDBOX ]
|
||||
then
|
||||
sandbox_color="%{$FG[149]%}"
|
||||
else
|
||||
sandbox_color="%{$FG[001]%}"
|
||||
fi
|
||||
echo $sandbox_color
|
||||
}
|
||||
|
||||
function colored_sandbox_string() {
|
||||
if [ is_zsh ]
|
||||
then
|
||||
sandbox_color=$(zsh_sandbox_color)
|
||||
else
|
||||
sandbox_color=$(bash_sandbox_color)
|
||||
fi
|
||||
echo $sandbox_color$(sandbox_prompt_info)
|
||||
}
|
Reference in New Issue
Block a user