# assume we want ssh commands to source this file if we are sourcing it,
# and we haven't specified otherwise already
[[ ! $BASH_LOGIN_SHELL ]] && export BASH_LOGIN_SHELL=true
+#BASH_LOGIN_SHELL=false # temporary override
# first conditions show that we are an ssh command without an interactive shell
if [[ $SSH_CONNECTION ]] \
# use extra globing features.
shopt -s extglob
# include .files when globbing, but ignore files name . and ..
-# setting this also sets dotglob
+# setting this also sets dotglob.
+# Note, this doesn't work in bash 4.4 anymore, for paths with
+# more than 1 directory, like a/b/.foo, since * is fixed to not match /
export GLOBIGNORE=*/.:*/..
# broken with bash_completion package. Saw a bug for this once. Don't anymore.
shopt -s checkwinsize
# attempt to save multiline single commands as single history entries.
shopt -s cmdhist
+# enable **
shopt -s globstar
# inside emacs fixes
-if [[ $INSIDE_EMACS ]]; then
+if [[ $RLC_INSIDE_EMACS ]]; then
# EMACS is used by bash on startup, but we don't need it anymore.
# plus I hit a bug in a makefile which inherited it
unset EMACS
- export INSIDE_EMACS
+ export RLC_INSIDE_EMACS
export PAGER=cat
export MANPAGER=cat
# scp completion does not work, but this doesn't fix it. todo, figure this out
if [[ $- == *i* ]]; then
# for readline-complete.el
- if [[ $INSIDE_EMACS ]]; then
+ if [[ $RLC_INSIDE_EMACS ]]; then
# all for readline-complete.el
stty echo
bind 'set horizontal-scroll-mode on'
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 *; *'
+# but meh. dunno why, but just " *" does glob expansion, so use [ ] to avoid it.
+HISTIGNORE='k *:[ ]*'
export BC_LINE_LENGTH=0
###################
## include files ###
###################
-
for _x in /a/bin/distro-functions/src/* /a/bin/!(githtml)/*-function?(s); do
source "$_x"
done
unset _x
# so I can share my bashrc
-for x in /a/bin/bash_unpublished/!(.#*); do source $x; done
+for x in /a/bin/bash_unpublished/source-!(.#*); do source $x; done
source $(dirname $(readlink -f $BASH_SOURCE))/path_add-function
source /a/bin/log-quiet/logq-function
path_add /a/exe
path_add --ifexists --end /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
-# todo, these need to be renamed to be less generic.
-# sync overrode something else useful
-#path_add $HOME/bin/bash-programs-by-ian/utils
+# based on readme.debian. dunno if this will break on other distros.
+_x=/usr/share/wcd/wcd-include.sh
+if [[ -e $_x ]]; then source $_x; fi
###############
-
#####################
### functions ####
#####################
+..() { c ..; }
+...() { c ../..; }
+....() { c ../../..; }
+.....() { c ../../../..; }
+......() { c ../../../../..; }
# file cut copy and paste, like the text buffers :)
ack() { ack-grep "$@"; }
+astudio() {
+ # googling android emulator libGL error: failed to load driver: r600
+ # lead to http://stackoverflow.com/a/36625175/14456
+ export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1
+ /a/opt/android-studio/bin/studio.sh "$@" &r;
+}
+
+b() {
+ # backwards
+ c -
+}
+
bashrcpush () {
local startdir="$PWD"
cd ~
tar cz bin/semi-private bin/distro-functions/src | ssh $x tar xz
done
cd $(mktemp -d)
- command cp /a/c/repos/bash/!(.git) ~/.gitconfig .
+ command cp /a/c/repos/bash/!(.git|..|.) ~/.gitconfig .
for x in "$@"; do
tar cz * | ssh $x tar xz
done
cd "$startdir"
}
+bkrun() {
+ # use -p from interactive shell
+ btrbk-run -p "$@"
+}
+
+bfg() { java -jar /a/opt/bfg-1.12.14.jar "$@"; }
+
+btc() {
+ local f=/etc/bitcoin/bitcoin.conf
+ bitcoin-cli -$(s grep rpcuser= $f) -$(s grep rpcpassword= $f) "$@"
+}
+
+if [[ $RLC_INSIDE_EMACS ]]; then
+ c() { wcd -z 50 -o "$@"; }
+else
+ # lets see what the fancy terminal does from time to time
+ c() { wcd -z 50 "$@"; }
+fi
+
caa() { git commit --amend --no-edit -a; }
calc() { echo "scale=3; $*" | bc -l; }
git commit -m "$*"
}
+cl() {
+ # choose recent directory. cl = cd list
+ c =
+}
+
d() { builtin bg; }
complete -A stopped -P '"%' -S '"' d
done < "$file"
}
+f() {
+ # cd forward
+ c +
+}
fa() {
# find array. make an array of file names found by find into $x
done < <(find "$@" -print0);
}
+faf() { # find all files
+ find $@ -type f
+}
+
+fastboot() { /a/opt/androidsdk/platform-tools/fastboot "$@"; }
ff() {
if type -P firefox &>/dev/null; then
}
feh() {
+ # F = fullscren, z = random, Z = auto zoom
command feh -FzZ "$@"
}
echo "${p%%/.git}"
}
+# quit will prompt if the program crashes.
+gmacs() { gdb -ex=r -ex=quit --args emacs "$@"; r; }
+
+gse() {
+ git send-email --notes '--envelope-sender=<ian@iankelling.org>' \
+ --suppress-cc=self "$@"
+}
+
gr() {
grep -iIP --color=auto "$@"
}
fi
}
+hstatus() {
+ # do git status on published repos
+ cd /a/bin/githtml
+ for x in !(forks) forks/* ian-specific/*; do
+ cd `readlink -f $x`/..
+ hr
+ echo $x
+ i status
+ cd /a/bin/githtml
+ done
+}
+
hl() { # history limit. Write extra history to archive file.
# todo: this is not working or not used currently
local max_lines linecount tempfile prune_lines x
echo
}
+hrcat() { local f; for f; do [[ -f $f ]] || continue; hr; echo "$f"; cat "$f"; done }
+
i() { git "$@"; }
# modified from ~/local/bin/git-completion.bash
git commit -am "$*"
}
+idea() {
+ /a/opt/idea-IC-163.7743.44/bin/idea.sh "$@" &r
+}
-ifn () {
+ifn() {
# insensitive find
- find -L . -iname "*$**" 2>/dev/null
+ find -L . -not \( -name .svn -prune -o -name .git -prune \
+ -o -name .hg -prune \) -iname "*$**" 2>/dev/null
}
grep -Il "" "$@" &>/dev/null
}
+jtail() {
+ journalctl -n 10000 -f "$@" | grep -Evi "^(\S+\s+){4}(sudo|sshd|cron)"
+}
+
l() {
if [[ $PWD == /[iap] ]]; then
mkdir() { command mkdir -p "$@"; }
pithos() {
- cd /a/opt/Pithosfly/
+ cd /
+ export PYTHONPATH=/a/opt/Pithosfly
python3 -m pithos&r
}
pwgen() {
+ # -m = min length
+ # -x = max length
+ # -t = print pronunciation
apg -m 12 -x 16 -t
}
}
rlu() { # [OPTS] HOST PATH
- # eg rlu -opts frodo testpath
+ # eg rlu -opts frodo /testpath
# useful for selectively sending dirs which have been synced with unison,
# where the path is the same on both hosts.
opts=("${@:1:$#-2}") # 1 to last -2
}
complete -F _root_command s sb
+scssl() {
+ # s gem install scss-lint
+ pushd /a/opt/thoughtbot-guides
+ git pull --stat
+ popd
+ scss-lint -c /a/opt/thoughtbot-guides/style/sass/.scss-lint.yml "$@"
+}
ser() {
local s; [[ $EUID != 0 ]] && s=sudo
ssh $1 /tmp/${2##*/} "${@:2}"
}
+swap() {
+ local tmp
+ tmp=$(mktemp)
+ mv $1 $tmp
+ mv $2 $1
+ mv $tmp $2
+}
+
t() {
local x
local -a args
return $ret
}
+testmail() {
+ declare -gi _seq; _seq+=1
+ echo "test body" | m mail -s "test mail from $HOSTNAME, $_seq" "${1:-root@localhost}"
+}
+
tm() {
# timer in minutes
- (sleep $(calc "$@ * 60") && mpv --volume 50 /a/bin/data/alarm.mp3) > /dev/null 2>&1 &
+ (sleep $(calc "$@ * 60") && mpv --volume 50 /a/bin/data/alarm.mp3 --loop=no) > /dev/null 2>&1 &
}
ts() { # start editing a new file
fi
}
-vc() {
- [[ $1 ]] || { e "$0: error, expected cmd to run"; return 1; }
- # manually run vpn so it stays within a network namespace,
- # until I get it all wired up with systemd.
- newns vpn start
- pid=$(< /run/openvpn/client.pid)
- vpn_on=false
- if [[ $pid ]]; then
- if [[ -e /proc/$pid ]]; then
- vpn_on=true
- else
- vpn_on=false
- s rm -f /run/openvpn/client.pid
- fi
- fi
- $vpn_on || s ip netns exec vpn /usr/sbin/openvpn --daemon ovpn --config /etc/openvpn/client.conf --cd /etc/openvpn --writepid /run/openvpn/client.pid
- gksudo -- ip netns exec vpn gksudo -u ${SUDO_USER:-$USER} "$@"
+psnetns() {
+ # show all processes in the network namespace $1.
+ # blank entries appear to be subprocesses/threads
+ local x netns
+ netns=$1
+ ps -w | head -n 1
+ s find -L /proc/[1-9]*/task/*/ns/net -samefile /run/netns/$netns | cut -d/ -f5 | \
+ while read l; do
+ x=$(ps -w --no-headers -p $l);
+ if [[ $x ]]; then echo "$x"; else echo $l; fi;
+ done
}
-transmission() {
- vc transmission-gtk&
- i=0
- while ((i < 10)); do
- tun_ip=$(s ip netns exec vpn ip a show dev tun0 | sed -rn 's/^ *inet (10\.8\.\S+).*/\1/p')
- [[ ! $tun_ip ]] || break
- sleep 1
- done
- echo "$0: tun_ip=$tun_ip"
- [[ $tun_ip ]] || { e "$0: error: no tun0 addr found"; return 1; }
- ssh dopub bash <<EOF
-set -e
-rule="-A PREROUTING -i eth0 -p tcp -m tcp --dport 63324 -j DNAT --to-destination $tun_ip:63324"
-found=false
-while read -r line; do
- if [[ \$line == \$rule ]] && ! \$found; then
- found=true
- else
- iptables -t nat -D \${line#-A}
- fi
-done < <(iptables -t nat -S | grep -E -- '--dport\s+63324')
-\$found || iptables -t nat \$rule
-EOF
+m() { printf "%s\n" "$*"; "$@"; }
+
+vpnbash() {
+ m s nsenter -t $(pgrep openvpn) -n -m bash
+ # note, if we wanted to run a graphical program,
+ # instead of bash, we could use
+ # gksudo -u ${SUDO_USER:-$USER} "$@"
}
+
+trg() { transmission-remote-gtk&r; }
+
+# transmission() {
+# local pid=$(cat /var/lib/transmission-daemon/transmission-daemon.pid)
+# if [[ $pid && -e /proc/$pid ]]; then
+# echo "noop. already running."
+# return
+# fi
+
+# local NAME=transmission-daemon
+# local DAEMON=/usr/bin/$NAME
+# local duser=debian-transmission
+
+# [ -e /etc/default/$NAME ] && . /etc/default/$NAME
+# s ip netns exec vpn sudo -u $duser ionice -c 3 nice -n 19 $DAEMON $OPTIONS
+# }
+
virshrm() {
for x in "$@"; do virsh destroy "$x"; virsh undefine "$x"; done
}
if [[ $- == *i* ]]; then
# commands to run when bash exits normally
- trap "hl; _smh" EXIT
+ trap "hl" EXIT
fi
shopt -s autocd
shopt -s dirspell
PS1='\w'
- if [[ $- == *i* ]] && [[ ! $INSIDE_EMACS ]]; then
+ if [[ $- == *i* ]] && [[ ! $RLC_INSIDE_EMACS ]]; then
PROMPT_DIRTRIM=2
bind -m vi-command B:shell-backward-word
bind -m vi-command W:shell-forward-word
prompt_command() {
local return=$? # this MUST COME FIRST
- local psc pst
- local ps_char ps_color
+ local psc pst ps_char ps_color stale_subvol
unset IFS
history -a # save history
+
+ # for titlebar
if [[ ! $DESKTOP_SESSION == xmonad && $TERM == *(screen*|xterm*|rxvt*) ]]; then
# from the screen man page
if [[ $TERM == screen* ]]; then
echo -ne "$title_escape${PWD/#$HOME/~} $USER@$HOSTNAME\007"
fi
+
case $return in
0) ps_color="$(get_term_color blue)"
ps_char='\$'
ps_color="$(get_term_color bold green)"
fi
fi
+ # I would set nullglob, but bash has had bugs where that
+ # doesn't work if not in top level.
+ if [[ -e /nocow/btrfs-stale ]] && ((`ls -AUq /nocow/btrfs-stale|wc -l`)); then
+ ps_char="! $ps_char"
+ fi
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)\] "
-
-
###########################################
# stuff that makes sense to be at the end #
###########################################
path_add --end ~/.npm-global
+
+# didn't get drush working, if I did, this seems like the
+# only good thing to include for it.
+# Include Drush completion.
+# if [ -f "/home/ian/.drush/drush.complete.sh" ] ; then
+# source /home/ian/.drush/drush.complete.sh
+# 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
+
+
# ensure no bad programs appending to this file will have an affect
return 0