From e3a5731e907ae95616afd1946ac372ebb6686e61 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Sun, 15 Feb 2015 17:41:51 -0800 Subject: [PATCH] various updates --- .bash_profile | 3 ++ .bashrc | 133 ++++++++++++++++++++++++++++++++++++++++---------- .profile | 4 ++ 3 files changed, 115 insertions(+), 25 deletions(-) diff --git a/.bash_profile b/.bash_profile index a2254a1..fd099aa 100644 --- a/.bash_profile +++ b/.bash_profile @@ -12,3 +12,6 @@ # the user to change. [[ -f ~/.bashrc ]] && . ~/.bashrc + + +[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* diff --git a/.bashrc b/.bashrc index ed0084b..f92ecc0 100644 --- a/.bashrc +++ b/.bashrc @@ -1,3 +1,4 @@ +PATH="$PATH:/opt/midfin/common/lib" # to debug #set -x # redirect output to log file @@ -43,7 +44,7 @@ fi # settings # ############ -CDPATH=.:/a +CDPATH=. # remove all aliases. aliases provided by the system tend to get in the way, # for example, error happens if I try to define a function the same name as an alias @@ -166,14 +167,17 @@ C_DEFAULT_DIR=/a ## include files ### ################### -for _x in $HOME/bin/bash-programs-by-ian/repos/*/*-function ~/opt/distro-functions/src/*; do +for _x in $HOME/bin/bash-programs-by-ian/repos/*/*-function ~/bin/distro-functions/src/*; do source "$_x" done unset _x source $HOME/bin/semi-private # so I can share my bashrc source $HOME/path_add-function -path_add --ifexists /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools -path_add $HOME/bin/bash-programs-by-ian/utils +path_add --ifexists --end /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools +path_add --ifexists --end /a/bin/sda/corpnext/cloudinit +# todo, these need to be renamed to be less generic. +# sync overrode something else useful +#path_add $HOME/bin/bash-programs-by-ian/utils source $HOME/mw_vars ############### @@ -204,20 +208,23 @@ alias hi='history' # note: gksudo is recommended for X apps because it does not set the -# home directory to the same. - -if [[ $- == *i* ]]; then - # extra space at the end allows aliases to work - alias s='SUDOD="$PWD" sudo -i ' -else - s() { - if [[ $EUID != 0 || $1 == -* ]]; then - SUDOD="$PWD" sudo -i "$@" - else - "$@" - fi - } -fi +# home directory to the same, and thus apps writing to ~ fuck things up +# with root owned files. + +# background +# alias s='SUDOD="$PWD" sudo -i ' +# because this is an alias, and the extra space at the end, it would allow +# aliases to be used with it. but aliases aren't used in scripts, +# better to eliminate inconsistencies. Plus, you can't do s=s; $s command +# with an alias, which I like to do in some functions +# extra space at the end allows aliases to work +s() { + if [[ $EUID != 0 || $1 == -* ]]; then + SUDOD="$PWD" sudo -i "$@" + else + "$@" + fi +} @@ -239,6 +246,8 @@ fi ### functions #### ##################### + + # netselect-apt finds a fast mirror. # but we need to replace the mirrors ourselves, # because it doesn't do that. best it can do is @@ -273,6 +282,7 @@ pdaemon () { fi } + a() { beet "${@}" } @@ -287,25 +297,32 @@ if type ack-grep >/dev/null 2>&1; then alias ack=ack-grep fi +postconfin() { + local MAPFILE + mapfile -t + local s + [[ $EUID == 0 ]] || s=s + $s postconf -v "${MAPFILE[@]}" +} gr() { - grep -i --binary-files=without-match --color=auto "$@" + grep -iI --color=auto "$@" } grr() { - grep -ri --binary-files=without-match --color=auto "$@" + grep -riI --color=auto "$@" } pub() { - rsync -rhc /a/h/_site/ li:/var/www/iankelling.org/public_html + rld /a/h/_site/ li:/var/www/iankelling.org/public_html } bashrcpush () { local startdir="$PWD" cd ~ for x in "$@"; do - ssh $x mkdir -p bin opt/distro-functions - tar cz bin/bash-programs-by-ian bin/semi-private opt/distro-functions/src | ssh $x tar xz + ssh $x mkdir -p bin/distro-functions/src + tar cz bin/bash-programs-by-ian bin/semi-private bin/distro-functions/src | ssh $x tar xz done cd $(mktemp -d) command cp /a/c/repos/bash/!(.git) ~/.gitconfig . @@ -315,6 +332,8 @@ bashrcpush () { cd "$startdir" } +whatismyip() { curl ipecho.net/plain ; echo; } + # history search k() { grep -P "$@" ${HISTFILE:-~/.bash_history} | tail -n 40; } @@ -484,7 +503,7 @@ i() { complete -o bashdefault -o default -o nospace -F _git i 2>/dev/null \ || complete -o default -o nospace -F _git i -# fast commit +# fast commit all ic() { git commit -am "$*" } @@ -764,6 +783,8 @@ sr() { fi } +rbpipe() { rbt post -o --diff-filename=- "$@"; } +rbp() { rbt post -o "$@"; } # log with script. timing is $1.t and script is $1.s @@ -794,6 +815,15 @@ splay() { # script replay } +# like -e for functions. returns on error. +# at the end of the function, disable with: +# trap ERR +funce() { + trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" } +${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?" +trap ERR +return' ERR +} # timer in minutes tm() { @@ -801,6 +831,18 @@ tm() { } +myunison() { + s unison -auto -owner -group +} + +tu() { + local s; + local dir="$(dirname "$1")" + if [[ -e $1 && ! -w $1 || ! -w $(dirname "$1") ]]; then + s=s; + fi + $s teeu "$@" +} ts() { # start editing a new file [[ $# != 1 ]] && echo "I need a filename." && return 1 local quiet @@ -882,7 +924,7 @@ complete -F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr hl() { # history limit. Write extra history to archive file. - local max_lines linecount tempfile prune_lines + local max_lines linecount tempfile prune_lines x local harchive="${HISTFILE}_archive" for x in "$HISTFILE" "$harchive"; do [[ -e $x ]] || { touch "$x" && echo "notice from hl(): creating $x"; } @@ -903,6 +945,24 @@ hl() { # history limit. Write extra history to archive file. fi } +############## work stuff ############# + +rn() { + pushd /sdx/test/sandbox/; + ./setup.sh; + ./run.sh; + popd +} + +vrm() { + virsh destroy $1 + virsh undefine $1 +} + + + + +############# some other section if [[ $- == *i* ]]; then # commands to run when bash exits normally trap "hl; _smh" EXIT @@ -1062,6 +1122,7 @@ fi ########################################### if [[ "$SUDOD" ]]; then cd "$SUDOD" + unset SUDOD elif [[ -d /a ]] && [[ $PWD == $HOME ]] && [[ $- == *i* ]]; then cd /a fi @@ -1075,3 +1136,25 @@ unset IFS if [[ $SOE ]]; then errcatch fi + +# I'd prefer to have system-wide, plus user ruby, due to bug in it +# https://github.com/rubygems/rubygems/pull/1002 +# further problems: installing multi-user ruby and user ruby, +# you don't get multi-user ruby when you sudo to root, unless its sudo -i. +# There a third hybrid form, which passenger error suggested I use, +# but it didn't actually work. + +# in cased I never need this +# rvm for non-interactive shell: modified from https://rvm.io/rvm/basics +#if [[ $(type -t rvm) == file && ! $(type -t ruby) ]]; then +# source $(rvm 1.9.3 do rvm env --path) +#fi + +# based on warning from rvmsudo +export rvmsudo_secure_path=1 + +if [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then + source "/usr/local/rvm/scripts/rvm" +fi +# make our last exit code be 0 +true diff --git a/.profile b/.profile index 6596cb5..a6429f1 100644 --- a/.profile +++ b/.profile @@ -1,2 +1,6 @@ # see .bashrc_profile for commentary echo this is ~/.profile, either my .bashrc_profile is unavailable or this is posix mode or not bash + +export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting + +[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* -- 2.30.2