From: Ian Kelling Date: Sat, 21 May 2016 20:02:43 +0000 (-0700) Subject: lots of updates X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=commitdiff_plain;h=45d6abc0df668267b44d39ab67ac9b8c6111e638 lots of updates --- diff --git a/.bash_profile b/.bash_profile index fd099aa..d3a6a8f 100644 --- a/.bash_profile +++ b/.bash_profile @@ -13,5 +13,5 @@ [[ -f ~/.bashrc ]] && . ~/.bashrc - -[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* +# ensure no bad programs appending to this file will have an affect +return 0 diff --git a/.bashrc b/.bashrc index f92ecc0..118a9cc 100644 --- a/.bashrc +++ b/.bashrc @@ -1,16 +1,15 @@ -PATH="$PATH:/opt/midfin/common/lib" # to debug #set -x -# redirect output to log file -#exec 1>/a/tmp/bashlog -#exec 2>/a/tmp/bashlog +# redirect output to log file. this doesn't work. todo figure out why +#exec 1>>/a/tmp/bashlog +#exec 2>>/a/tmp/bashlog # By default this file is sourced for ALL ssh commands. This is wonky. -# Normally, this file is not sourced when a script is run, but we can override -# that by having #!/bin/bash -l. -# I want something similar for ssh commands. when a local script runs an ssh command, -# this file should not be sourced by default, but we should be able to override that. +# Normally, this file is not sourced when a script is run, but we can +# override that by having #!/bin/bash -l. I want something similar for ssh +# commands. when a local script runs an ssh command, this file should not be +# sourced by default, but we should be able to override that. # # so here we test for conditions of a script under ssh and return if so. To test # for an overriding condition, we have a few options. one is to use an @@ -34,10 +33,17 @@ if [[ $SSH_CONNECTION ]] \ && [[ $- != *i* ]] \ && [[ ! $BASH_LOGIN_SHELL == true ]]; then return +else + source /etc/profile fi +# note, to catch errors in functions but not outside, do: +# set -E -o pipefail +# trap return ERR +# trap 'trap ERR' RETURN + ############ @@ -65,7 +71,8 @@ export GLOBIGNORE=*/.:*/.. # still broken in wheezy # still buggered in latest stable from the web, version 2.1 # perhaps its fixed in newer git version, which fails to make for me -# this note is from 6-2014 +# this note is from 6-2014. +# Also, enabling this before sourcing .bashrc makes PATH be empty. #shopt -s nullglob # make tab on an empty line do nothing @@ -150,7 +157,7 @@ HISTCONTROL=ignoredups # works in addition to HISTCONTROL to do more flexible things # it could also do the same things as HISTCONTROL and thus replace it, # but meh -HISTIGNORE="k *" +HISTIGNORE='k *; *' export BC_LINE_LENGTH=0 @@ -161,24 +168,22 @@ export BC_LINE_LENGTH=0 C_DEFAULT_DIR=/a - - ################### ## include files ### ################### -for _x in $HOME/bin/bash-programs-by-ian/repos/*/*-function ~/bin/distro-functions/src/*; do +for _x in /a/bin/distro-functions/src/* /a/bin/bash-programs-by-ian/repos/*/*-function; do source "$_x" done unset _x -source $HOME/bin/semi-private # so I can share my bashrc -source $HOME/path_add-function +source /a/bin/semi-private # so I can share my bashrc +source $(dirname $(readlink -f $BASH_SOURCE))/path_add-function 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 + +[[ -e $HOME/mw_vars ]] && source $HOME/mw_vars ############### ### aliases ### @@ -247,39 +252,28 @@ fi ##################### +sdf() { + c /sdx/test/sandbox/ +} -# 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 -# output a basic sources file -# here we get the server it found, get the main server we use -# then substitute all instances of one for the other in the sources file -# and backup original to /etc/apt/sources.list-original. -# this is idempotent debian_pick_mirror () { - local x=$(mktemp -d)/f # safe way to get file name without creating one - sudo netselect-apt -o "$x" || return 1 - x=$(_debian_pick_mirror_grep stable "$x") + # 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 + # output a basic sources file + # here we get the server it found, get the main server we use + # then substitute all instances of one for the other in the sources file + # and backup original to /etc/apt/sources.list-original. + # this is idempotent. the only way to identify debian sources is to + # note the original server, so we put it in a comment so we can + # identify it later. + local file=$(mktemp -d)/f # safe way to get file name without creating one + sudo netselect-apt -o "$file" || return 1 + url=$(grep ^\\w $file | head -n1 | awk '{print $2}') sudo cp -f /etc/apt/sources.list /etc/apt/sources.list-original - sudo sed -i "s/$(_debian_pick_mirror_grep wheezy)/$x/" /etc/apt/sources.list - aptitude update -} - -_debian_pick_mirror_grep () { - local x="$(grep -oP "^deb [^ ]+ $1 " ${2-/etc/apt/sources.list})" - x="${x#deb }" - x="${x% $1 }" - # replace / with \/ so we can use it with sed - echo "${x//\//\\/}" -} -# portable daemon, for debian & fedora -pdaemon () { - if isdeb; then - sudo /etc/init.d/$1 $2 - else - sudo systemctl $2 $1.service - fi + sudo sed -ri "/http.us.debian.org/ s@( *[^ #]+ +)[^ ]+([^#]+).*@\1$url\2# http.us.debian.org@" /etc/apt/sources.list + sudo apt-get update } @@ -287,9 +281,24 @@ a() { beet "${@}" } +dus() { + du -sh ${@:-*} | sort -h +} t() { - trash-put "$@" + local x + local -a args + if type -t trash-put >/dev/null; then + # skip args that don't exist, or else it's an err + for x in "$@"; do [[ ! -e $x ]] || args+=("$x"); done + [[ ! ${args[@]} ]] || trash-put "${args[@]}" + else + rm -rf "$@" + fi +} + +ccat () { # config cat. see a config without extra lines. + grep '^\s*[^[:space:]#]' "$@" } @@ -302,21 +311,65 @@ postconfin() { mapfile -t local s [[ $EUID == 0 ]] || s=s - $s postconf -v "${MAPFILE[@]}" + $s postconf -ev "${MAPFILE[@]}" +} + + +tclock() { + clear + date +%l:%_M + len=60 + # this goes to full width + #len=${1:-$((COLUMNS -7))} + x=1 + while true; do + if (( x == len )); then + end=true + d="$(date +%l:%_M) " + else + end=false + d=$(date +%l:%M:%_S) + fi + echo -en "\r" + echo -n "$d" + for ((i=0; i> "$2" - pastline="$line" - else - pastline="$pastline $line" - fi - done + # remove leading spaces/tabs. assumes extglob + if [[ $line == "[ ]*" ]]; then + line="${line##+( )}" + fi + if $first; then + pastline="$line" + first=false + elif [[ $line == *=* ]]; then + echo "$pastline" >> "$2" + pastline="$line" + else + pastline="$pastline $line" + fi + done echo "$pastline" >> "$2" } @@ -510,7 +587,7 @@ ic() { # insensitive find ifn () { - find . -iname '*'"$*"'*' + find -L . -iname "*$**" 2>/dev/null } @@ -596,7 +673,7 @@ perm_fix() { if [[ $EUID == 0 ]]; then te "$1" || touch "$1" if [[ $(stat -c "%u" "$1") == 0 ]] ; then - argdir=$(getdir "$1") + argdir=$(dirname "$1") if [[ $(stat -c "%u" "$argdir") != 0 ]] ; then if ! chown "--reference=$argdir" "$1"; then echo failed to fix bad ownership file permissons @@ -705,26 +782,37 @@ pfind() { #find *$1* in $PATH # do pwd + some other info. #pwd() { echo "$(ll -d "$PWD") $USER@$HOSTNAME $(date +%r)"; } - -pwgen() { # generate a random password, with digits & punctuation and without - arg=${1:-50} - head -c 200 /dev/urandom | tr -cd '[:graph:]' | head -c "$arg" - echo - head -c 200 /dev/urandom | tr -cd '[:alnum:]' | head -c "$arg" - head -c 5 /dev/urandom | tr -cd '[:alpha:]' | head -c "$arg" - echo -} - q() { # start / launch a program in the backround and redir output to null "$@" &> /dev/null & } - +pwgen() { + apg -s -m 10 -x 14 -t +} r() { exit "$@" 2>/dev/null } +# connect to vms made with virt-install +vspicy() { + spicy -p $(sudo virsh dumpxml "$1"|grep "/dev/null; then + service() { + echo actually running: systemctl $2 $1 + systemctl $2 $1 + } +fi # use sb instead of s is for sudo redirections, eg. sb 'echo "ok fine" > /etc/file' sb() { @@ -830,11 +949,44 @@ tm() { (sleep $(calc "$@ * 60") && mpv --volume 50 /a/bin/data/alarm.mp3) > /dev/null 2>&1 & } +ser() { + local s; [[ $EUID != 0 ]] && s=sudo + if type -p systemctl &>/dev/null; then + $s systemctl $1 $2 + else + $s service $2 $1 + fi +} -myunison() { - s unison -auto -owner -group +sgo() { # service go + service=$1 + ser start $service + if type -p systemctl &>/dev/null; then + ser enable $service + fi +} + + +vm-set-listen(){ + local t=$(mktemp) + local vm=$1 + local ip=$2 + s virsh dumpxml $vm | sed -r "s/((ssh frodo bash -l) >(bash -l) >(ssh x2 bash -l) >(ssh tp bash -l) +} +da() { # do all + local host + "$@" + for host in x2 tp treetowl; do + ssh $host "$@" + done + +} + +istext() { + grep -Il "" "$@" &>/dev/null +} if [[ $OS == Windows_NT ]]; then # cygstart wrapper @@ -915,7 +1087,12 @@ else } fi - +khfix() { # known hosts fix + ssh-keygen -R $1 + local x=$(host $1) + ssh-keygen -R ${x##* } + ssh $1 : +} # todo, update this @@ -949,8 +1126,7 @@ hl() { # history limit. Write extra history to archive file. rn() { pushd /sdx/test/sandbox/; - ./setup.sh; - ./run.sh; + ./setup.sh && ./run.sh popd } @@ -1045,7 +1221,7 @@ if [[ $- == *i* ]]; then if [[ $OS != Windows_NT ]]; then GIT_PS1_SHOWDIRTYSTATE=true fi - # arch source location + # arch source lopip show -fcation [[ -r /usr/share/git/git-prompt.sh ]] && source /usr/share/git/git-prompt.sh # fedora/debian source [[ -r /usr/share/git-core/contrib/completion/git-prompt.sh ]] && source /usr/share/git-core/contrib/completion/git-prompt.sh @@ -1079,7 +1255,6 @@ if [[ $- == *i* ]]; then local ps_char ps_color unset IFS history -a # save history - history -n # read any new history if [[ ! $DESKTOP_SESSION == xmonad && $TERM == *(screen*|xterm*|rxvt*) ]]; then # from the screen man page if [[ $TERM == screen* ]]; then @@ -1108,7 +1283,9 @@ if [[ $- == *i* ]]; then ps_color="$(get_term_color bold green)" fi fi - PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] " + PS1="${PS1%"${PS1#*[wW]}"} \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] " + # emacs completion doesn't like the git prompt atm, so disabling it. + #PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] " } PROMPT_COMMAND=prompt_command fi @@ -1153,8 +1330,18 @@ fi # based on warning from rvmsudo export rvmsudo_secure_path=1 -if [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then + +if [[ -s "/usr/local/rvm/scripts/rvm" ]]; then source "/usr/local/rvm/scripts/rvm" +elif [[ -s $HOME/.rvm/scripts/rvm ]]; then + source $HOME/.rvm/scripts/rvm +fi + +# https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login +# i added an extra condition as gentoo xorg guide says depending on +# $DISPLAY is fragile. +if [[ ! $DISPLAY && $XDG_VTNR == 1 ]] && shopt -q login_shell && isarch; then + exec startx fi -# make our last exit code be 0 -true +# ensure no bad programs appending to this file will have an affect +return 0 diff --git a/.inputrc b/.inputrc index 76a38b2..c47fe94 100644 --- a/.inputrc +++ b/.inputrc @@ -24,7 +24,7 @@ set show-all-if-unmodified on # nice in bash, but messes up completion in emacs shell #set visible-stats on -set visible-stats offmv f +set visible-stats off # turn off pager for completion set page-completions off diff --git a/path_add-function b/path_add-function index 0edf2bb..0dbaf9f 100644 --- a/path_add-function +++ b/path_add-function @@ -9,7 +9,7 @@ path_add() { --end: adds to end of path, which will give it lowest priority --ifexists: add to path only if the directory exists" local found x y z ifexists end loop newpath - ifexists=false + force=false end=false loop=true # portable substring matching is ugly http://mywiki.wooledge.org/BashFAQ/041 @@ -18,8 +18,8 @@ path_add() { --*) if [ "$1" = --end ]; then end=true - elif [ "$1" = --ifexists ]; then - ifexists=true + elif [ "$1" = --force ]; then + force=true elif [ "$1" = --help ]; then echo "$help" return @@ -53,7 +53,8 @@ path_add() { unset IFS PATH="$newpath" for x in "$@"; do - if ! $ifexists || [ -d "$x" ]; then + x="$(readlink -f "$x")" + if $force || [ -d "$x" ]; then if [ ! "$PATH" ]; then PATH="$x" elif $end; then