1 PATH="$PATH:/opt/midfin/common/lib"
4 # redirect output to log file
9 # By default this file is sourced for ALL ssh commands. This is wonky.
10 # Normally, this file is not sourced when a script is run, but we can override
11 # that by having #!/bin/bash -l.
12 # I want something similar for ssh commands. when a local script runs an ssh command,
13 # this file should not be sourced by default, but we should be able to override that.
15 # so here we test for conditions of a script under ssh and return if so. To test
16 # for an overriding condition, we have a few options. one is to use an
17 # environment variable. env variables sent across ssh are strictly limited. ssh
18 # -t which sets $SSH_TTY, but within a script that won't work because tty
19 # allocation will fail. We could override an obscure unused LC_var, like
20 # telephone, but I don't want to run into some edge case where that messes
21 # things up. we could transfer a file which we could test for, but I can't think
22 # of a way to make that inherently limited to a single ssh command. I choose to
23 # set SendEnv and AcceptEnv ssh config vars to allow the environment variable
24 # BASH_LOGIN_SHELL to propagate across ssh.
26 # assume we want ssh commands to source this file if we are sourcing it,
27 # and we haven't specified otherwise already
28 [[ ! $BASH_LOGIN_SHELL ]] && export BASH_LOGIN_SHELL=true
30 # first conditions show that we are an ssh command without an interactive shell
31 if [[ $SSH_CONNECTION ]] \
35 && [[ ! $BASH_LOGIN_SHELL == true ]]; then
49 # remove all aliases. aliases provided by the system tend to get in the way,
50 # for example, error happens if I try to define a function the same name as an alias
53 # remove gnome keyring warning messages
54 # there is probably a more proper way, but I didn't find any easily on google
55 # now using xfce+xmonad instead of vanilla xmonad, so disabling this
56 #unset GNOME_KEYRING_CONTROL
58 # use extra globing features.
60 # include .files when globbing, but ignore files name . and ..
61 # setting this also sets dotglob
62 export GLOBIGNORE=*/.:*/..
64 # broken with bash_completion package. Saw a bug for this once. Don't anymore.
65 # still broken in wheezy
66 # still buggered in latest stable from the web, version 2.1
67 # perhaps its fixed in newer git version, which fails to make for me
68 # this note is from 6-2014
71 # make tab on an empty line do nothing
72 shopt -s no_empty_cmd_completion
75 # http://bash-completion.alioth.debian.org/
76 # might be sourced by the system already, but I've noticed it not being sourced before
77 if ! type _init_completion &> /dev/null && [[ -r "/usr/share/bash-completion/bash_completion" ]]; then
78 . /usr/share/bash-completion/bash_completion
82 # fix spelling errors for cd, only in interactive shell
84 # append history instead of overwritting it
86 # for compatibility, per gentoo/debian bashrc
88 # attempt to save multiline single commands as single history entries.
94 if [[ $INSIDE_EMACS ]]; then
95 # EMACS is used by bash on startup, but we don't need it anymore.
96 # plus I hit a bug in a makefile which inherited it
101 # scp completion does not work, but this doesn't fix it. todo, figure this out
102 complete -r scp &> /dev/null
103 # todo, remote file completion fails, figure out how to turn it off
107 if [[ $- == *i* ]]; then
108 # for readline-complete.el
109 if [[ $INSIDE_EMACS ]]; then
110 # all for readline-complete.el
112 bind 'set horizontal-scroll-mode on'
113 bind 'set print-completions-horizontally on'
114 bind '"\C-i": self-insert'
116 # arrow keys. for other terminals, see http://unix.stackexchange.com/questions/10806/how-to-change-previous-next-word-shortcut-in-bash
117 if [[ $TERM == "xterm" ]]; then
118 bind '"\e[1;5C": shell-forward-word' 2>/dev/null
119 bind '"\e[1;5D": shell-backward-word' 2>/dev/null
121 bind '"\eOc": shell-forward-word'
122 bind '"\eOd": shell-backward-word'
124 # terminal keys: C-c, C-z. the rest defined by stty -a are, at least in
125 # gnome-terminal, overridden by bash, or disabled by the system
126 stty werase undef lnext undef stop undef start undef
133 # history number. History expansion is good.
135 # history file size limit, set to unlimited.
136 # this needs to be different from the default because
137 # default HISTFILESIZE is 500 and could clobber our history
139 # max commands 1 session can append/read from history
141 # my own history size limit based on lines
142 HISTFILELINES=1000000
144 # the time format display when doing the history command
145 # also, setting this makes the history file record time
146 # of each command as seconds from the epoch
147 HISTTIMEFORMAT="%I:%M %p %m/%d "
148 # consecutive duplicate lines don't go in history
149 HISTCONTROL=ignoredups
150 # works in addition to HISTCONTROL to do more flexible things
151 # it could also do the same things as HISTCONTROL and thus replace it,
155 export BC_LINE_LENGTH=0
158 # note, if I use a machine I don't want files readable by all users, set
159 # umask 077 # If fewer than 4 digits are entered, leading zeros are assumed
170 for _x in $HOME/bin/bash-programs-by-ian/repos/*/*-function ~/bin/distro-functions/src/*; do
174 source $HOME/bin/semi-private # so I can share my bashrc
175 source $HOME/path_add-function
176 path_add --ifexists --end /a/opt/adt-bundle*/tools /a/opt/adt-bundle*/platform-tools
177 path_add --ifexists --end /a/bin/sda/corpnext/cloudinit
178 # todo, these need to be renamed to be less generic.
179 # sync overrode something else useful
180 #path_add $HOME/bin/bash-programs-by-ian/utils
187 # disabled for now, but these are generally good
188 # if [[ $- == *i* ]]; then
193 # remove any default aliases for these
194 alias ls > /dev/null 2>&1 && unalias ls
195 alias ll > /dev/null 2>&1 && unalias ll
196 alias grep > /dev/null 2>&1 && unalias grep
200 command mkdir -p "$@"
205 complete -A stopped -P '"%' -S '"' d
210 # note: gksudo is recommended for X apps because it does not set the
211 # home directory to the same, and thus apps writing to ~ fuck things up
212 # with root owned files.
215 # alias s='SUDOD="$PWD" sudo -i '
216 # because this is an alias, and the extra space at the end, it would allow
217 # aliases to be used with it. but aliases aren't used in scripts,
218 # better to eliminate inconsistencies. Plus, you can't do s=s; $s command
219 # with an alias, which I like to do in some functions
220 # extra space at the end allows aliases to work
222 if [[ $EUID != 0 || $1 == -* ]]; then
223 SUDOD="$PWD" sudo -i "$@"
231 if [[ $OS == Windows_NT ]]; then
232 alias ffs='cygstart "/c/Program Files (x86)/Mozilla Firefox/firefox.exe" -P scratch'
234 alias j='command cygpath'
235 alias t='command cygstart'
236 alias cygstart='echo be quick, use the alias "t" instead :\)'
237 alias cygpath='echo be quick, use the alias "j" instead :\)'
245 #####################
247 #####################
251 # netselect-apt finds a fast mirror.
252 # but we need to replace the mirrors ourselves,
253 # because it doesn't do that. best it can do is
254 # output a basic sources file
255 # here we get the server it found, get the main server we use
256 # then substitute all instances of one for the other in the sources file
257 # and backup original to /etc/apt/sources.list-original.
259 debian_pick_mirror () {
260 local x=$(mktemp -d)/f # safe way to get file name without creating one
261 sudo netselect-apt -o "$x" || return 1
262 x=$(_debian_pick_mirror_grep stable "$x")
263 sudo cp -f /etc/apt/sources.list /etc/apt/sources.list-original
264 sudo sed -i "s/$(_debian_pick_mirror_grep wheezy)/$x/" /etc/apt/sources.list
268 _debian_pick_mirror_grep () {
269 local x="$(grep -oP "^deb [^ ]+ $1 " ${2-/etc/apt/sources.list})"
272 # replace / with \/ so we can use it with sed
276 # portable daemon, for debian & fedora
279 sudo /etc/init.d/$1 $2
281 sudo systemctl $2 $1.service
296 if type ack-grep >/dev/null 2>&1; then
304 [[ $EUID == 0 ]] || s=s
305 $s postconf -v "${MAPFILE[@]}"
309 grep -iI --color=auto "$@"
313 grep -riI --color=auto "$@"
317 rld /a/h/_site/ li:/var/www/iankelling.org/public_html
321 local startdir="$PWD"
324 ssh $x mkdir -p bin/distro-functions/src
325 tar cz bin/bash-programs-by-ian bin/semi-private bin/distro-functions/src | ssh $x tar xz
328 command cp /a/c/repos/bash/!(.git) ~/.gitconfig .
330 tar cz * | ssh $x tar xz
335 whatismyip() { curl ipecho.net/plain ; echo; }
338 k() { grep -P "$@" ${HISTFILE:-~/.bash_history} | tail -n 40; }
340 calc() { echo "scale=3; $*" | bc -l; }
343 # setup for format of postfix
349 local unified="$(mktemp)"
353 _cdiff-prep "$1" "$f1"
354 _cdiff-prep "$2" "$f2"
355 cat "$f1" "$f2" | grep -Po '^[^=]+=' | sort | uniq > "$unified"
356 while IFS= read -r line; do
357 # the default bright red / blue doesn't work in emacs shell
358 dwdiff -cblue,red -A best -d " ," <(grep "^$line" "$f1" || echo ) <(grep "^$line" "$f2" || echo ) | colordiff
363 # join options which are continued to multiples lines onto one line
366 grep -vE '^([ \t]*#|^[ \t]*$)' "$1" | while IFS= read -r line; do
367 # remove leading spaces/tabs. assumes extglob
368 if [[ $line == "[ ]*" ]]; then
374 elif [[ $line == *=* ]]; then
375 echo "$pastline" >> "$2"
378 pastline="$pastline $line"
381 echo "$pastline" >> "$2"
384 # makes it so chown -R symlink affects the symlink and its target.
386 if [[ $1 == -R ]]; then
388 command chown -h "$@"
390 command chown -RH "$@"
400 if [[ $# == 0 ]]; then
401 cp /a/bin/data/COPYING .
403 cp /a/bin/data/COPYING "$@"
409 diff --strip-trailing-cr -w "$@" # diff content
414 date "+%A, %B %d, %r" "$@"
421 envload() { # load environment from a previous: export > file
422 local file=${1:-$HOME/.${USER}_env}
423 eval "$(export | sed 's/^declare -x/export -n/')"
424 while IFS= read -r line; do
425 # declare -x makes variables local to a function
426 eval ${line/#declare -x/export}
432 # havn't tested these:
433 #file cut copy and paste, like the text buffers :)
434 _fbufferinit() { # internal use by
435 ! [[ $my_f_tempdir ]] && my_f_tempdir=$(mktemp -d)
436 rm -rf "$my_f_tempdir"/*
440 cp "$@" "$my_f_tempdir"/
444 mv "$@" "$my_f_tempdir"/
446 fpst() { # file paste
447 [[ $2 ]] && { echo too many arguments; return 1; }
449 cp "$my_f_tempdir"/* "$target"
453 # find array. make an array of file names found by find into $x
454 # argument: find arguments
455 # return: find results in an array $x
457 while read -rd ''; do
459 done < <(find "$@" -print0);
463 git_empty_branch() { # start an empty git branch. carefull, it deletes untracked files.
464 [[ $# == 1 ]] || { echo 'need a branch name!'; return 1;}
466 gitroot || return 1 # function to set gitroot
467 builtin cd "$gitroot"
468 git symbolic-ref HEAD refs/heads/$1
475 if type -P firefox &>/dev/null; then
483 firefox -P default "$@" >/dev/null 2>&1
487 firefox -P alt "$@" >/dev/null 2>&1
494 # horizontal row. used to break up output
495 hr() { printf "$(tput setaf 5)â–ˆ$(tput sgr0)%.0s" $(seq $COLUMNS); }
501 # modified from ~/local/bin/git-completion.bash
502 # other completion commands are mostly taken from bash_completion package
503 complete -o bashdefault -o default -o nospace -F _git i 2>/dev/null \
504 || complete -o default -o nospace -F _git i
513 find . -iname '*'"$*"'*'
520 if [[ $PWD == /[iap] ]]; then
521 command ls -A --color=auto -I lost+found "$@"
523 command ls -A --color=auto "$@"
529 lld() { ll -d "$@"; }
532 low() { # make filenames all lowercase
535 y=$(tr "[A-Z]" "[a-z]" <<<"$x")
536 [[ $y != $x ]] && mv "$x" "$y"
541 lower() { # make first letter of filenames lowercase.
544 if [[ ${x::1} == [A-Z] ]]; then
545 y=$(tr "[A-Z]" "[a-z]" <<<"${x::1}")"${x:1}"
546 safe_rename "$x" "$y"
552 if [[ $# != 2 ]]; then
553 echo safe_rename error: $# args, need 2 >2
555 elif [[ $1 != $2 ]]; then
557 echo Cannot rename "$1" to "$2" as it already exists.
568 safe_rename "$x" "$y"
576 # test existence / exists
580 [[ -e "$x" || -L "$x" ]] || ret=1
585 # show make targets, via http://stackoverflow.com/questions/3063507/list-goals-targets-in-gnu-make
587 make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
591 # fix root file ownership for FILE argument.
592 # check if parent or grandparent is not root and if the dir of FILE is also
593 # owned by that user, and change ownership to that user
596 if [[ $EUID == 0 ]]; then
597 te "$1" || touch "$1"
598 if [[ $(stat -c "%u" "$1") == 0 ]] ; then
599 argdir=$(getdir "$1")
600 if [[ $(stat -c "%u" "$argdir") != 0 ]] ; then
601 if ! chown "--reference=$argdir" "$1"; then
602 echo failed to fix bad ownership file permissons
610 # see notes for usage
613 local dname="${PWD##*/}"
614 local m="/a/tmp/$dname-missing"
615 local d="/a/tmp/$dname-diff"
616 [[ -e $d ]] && rm "$d"
617 [[ -e $m ]] && rm "$m"
620 while read -r line; do
622 if [[ -e "$fsfile" ]]; then
623 md5diff "$line" "$fsfile" && tee -a "/a/tmp/$dname-diff" <<< "$fsfile $line"
629 done < <(find -type f )
632 (( msize <= 100 )) && cat $m
644 echo different > $x/c/d
648 # expected output, with different tmp dirs
649 # /tmp/tmp.HDPbwMqdC9/c/d ./c/d
650 # /a/tmp/tmp.qLDkYxBYPM-missing
654 # test whether missing files were renamed, generally for use with fsdiff
655 # $1 = fsdiff output file, $2 = directory to compare to. pwd = fsdiff dir
656 # echos non-renamed files
661 { sums+=( "$(md5sum < "$x")" ) ; } 2>/dev/null
663 while read -r line; do
664 { missing_sum=$(md5sum < "$line") ; } 2>/dev/null
666 for x in "${sums[@]}"; do
667 if [[ $missing_sum == "$x" ]]; then
672 $renamed || echo "$line"
678 # get a random string
679 #par2rbase=$(head -c 50 /dev/urandom | tr -cd '[:alpha:]')
681 [[ $par2rbase ]] || { echo "set \$par2rbase first"; return 1; }
686 par2 c QDLDeDJ6z4.par2 *
694 [[ $(md5sum < "$1") != $(md5sum < "$2") ]]
698 pfind() { #find *$1* in $PATH
699 [[ $# != 1 ]] && { echo requires 1 argument; return 1; }
701 IFS=: pathArray=($PATH); unset IFS
702 find "${pathArray[@]}" -iname "*$1*"
705 # do pwd + some other info.
706 #pwd() { echo "$(ll -d "$PWD") $USER@$HOSTNAME $(date +%r)"; }
709 pwgen() { # generate a random password, with digits & punctuation and without
711 head -c 200 /dev/urandom | tr -cd '[:graph:]' | head -c "$arg"
713 head -c 200 /dev/urandom | tr -cd '[:alnum:]' | head -c "$arg"
714 head -c 5 /dev/urandom | tr -cd '[:alpha:]' | head -c "$arg"
718 q() { # start / launch a program in the backround and redir output to null
725 exit "$@" 2>/dev/null
728 # trash-restore lists everything that has been trashed at or below CWD
729 # This picks out files just in CWD, not subdirectories,
730 # which also match grep $1, usually use $1 for a time string
731 # which you get from running restore-trash once first
735 # last condition is to not ask again for ones we skipped
736 while name="$( echo | restore-trash | gr "$PWD/[^/]\+$" | gr "$1" )" \
737 && [[ $name ]] && (( $(wc -l <<<"$name") >= nth )); do
738 name="$(echo "$name" | head -n $nth | tail -n 1 )"
739 read -p "$name [Y/n] " ask
740 if [[ ! $ask || $ask == [Yy] ]]; then
741 x=$( echo "$name" | gr -o "^\s*[0-9]*" )
742 echo $x | restore-trash > /dev/null
743 elif [[ $ask == [Nn] ]]; then
751 # rsync, root is required to keep permissions right.
752 # rsync --archive --human-readable --verbose --itemize-changes --checksum \(-ahvic\) \
753 # --no-times --delete
754 # basically, make an exact copy, use checksums instead of file times to be more accurate
755 rl() { rsync -ahvic --delete "$@"; }
756 # don't delete files on the target end which do not exist on the original end:
757 rld() { rsync -ahvic "$@"; }
758 complete -F _rsync -o nospace rld rlt fl
759 # rl without preserving modification time. for some reason I had this as default before.
760 # perhaps that reason will come up again and I will document it.
761 rlt() { rsync -ahvic --delete --no-t "$@"; }
765 # use sb instead of s is for sudo redirections, eg. sb 'echo "ok fine" > /etc/file'
770 complete -F _root_command s sb
772 # use -ll, less secure but faster.
777 # sudo redo. be aware, this command may not work right on strange distros or earlier software
779 if [[ $# == 0 ]]; then
780 sudo -E bash -c -l "$(history -p '!!')"
782 echo this command redos last history item. no argument is accepted
786 rbpipe() { rbt post -o --diff-filename=- "$@"; }
787 rbp() { rbt post -o "$@"; }
790 # log with script. timing is $1.t and script is $1.s
791 # -l to save to ~/typescripts/
792 # -t to add a timestamp to the filenames
794 local logdir do_stamp arg_base
795 (( $# >= 1 )) || { echo "arguments wrong"; return 1; }
798 while getopts "lt" option
801 l ) arg_base=$logdir ;;
805 shift $(($OPTIND - 1))
807 [[ -e $logdir ]] || mkdir -p $logdir
808 $do_stamp && arg_base+=$(date +%F.%T%z)
809 script -t $arg_base.s 2> $arg_base.t
811 splay() { # script replay
812 #logRoot="$HOME/typescripts/"
813 #scriptreplay "$logRoot$1.t" "$logRoot$1.s"
814 scriptreplay "$1.t" "$1.s"
818 # like -e for functions. returns on error.
819 # at the end of the function, disable with:
822 trap 'echo "${BASH_COMMAND:+BASH_COMMAND=\"$BASH_COMMAND\" }
823 ${FUNCNAME:+FUNCNAME=\"$FUNCNAME\" }${LINENO:+LINENO=\"$LINENO\" }\$?=$?"
830 (sleep $(calc "$@ * 60") && mpv --volume 50 /a/bin/data/alarm.mp3) > /dev/null 2>&1 &
835 s unison -auto -owner -group
840 local dir="$(dirname "$1")"
841 if [[ -e $1 && ! -w $1 || ! -w $(dirname "$1") ]]; then
846 ts() { # start editing a new file
847 [[ $# != 1 ]] && echo "I need a filename." && return 1
849 if [[ $- != *i* ]]; then
852 if [[ $1 == *.c ]]; then
853 e '#include <stdio.h>' >"$1"
854 e '#include <stdlib.h>' >>"$1"
855 e 'int main(int argc, char * argv[]) {' >>"$1"
856 e ' printf( "hello world\n");' >>"$1"
857 e ' return 0;' >>"$1"
859 e "${1%.c}: $1" > Makefile
860 e " g++ -ggdb -std=gnu99 -o ${1%.c} $<" >> Makefile
861 e "#!/bin/bash" >run.sh
862 e "./${1%.c}" >>run.sh
864 elif [[ $1 == *.java ]]; then
865 e "public class ${1%.*} {" >"$1"
866 e ' public static void main(String[] args) {' >>"$1"
867 e ' System.out.println("Hello, world!");' >>"$1"
872 echo "#!/bin/bash" > "$1"
875 [[ $quiet ]] || g "$1"
879 tx() { # toggle set -x, and the prompt so it doesn't spam
880 if [[ $- == *x* ]]; then
882 PROMPT_COMMAND=prompt_command
893 if [[ $OS == Windows_NT ]]; then
904 (( ${#x[#]} > 1 )) && { echo "warning ${#x[#]} matches found"; sleep 1; }
909 if type gvfs-open &> /dev/null ; then
914 # another alternative is run-mailcap
922 complete -F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
926 hl() { # history limit. Write extra history to archive file.
927 local max_lines linecount tempfile prune_lines x
928 local harchive="${HISTFILE}_archive"
929 for x in "$HISTFILE" "$harchive"; do
930 [[ -e $x ]] || { touch "$x" && echo "notice from hl(): creating $x"; }
931 if [[ ! $x || ! -e $x || ! -w $x || $(stat -c "%u" "$x") != $EUID ]]; then
932 echo "error in hl: history file \$x:$x no good"
936 history -a # save history
937 max_lines=$HISTFILELINES
938 [[ $max_lines =~ ^[0-9]+$ ]] || { echo "error in hl: failed to get max line count"; return 1; }
939 linecount=$(wc -l < $HISTFILE) # pipe so it doesn't output a filename
940 [[ $linecount =~ ^[0-9]+$ ]] || { echo "error in hl: wc failed"; return 1; }
941 if (($linecount > $max_lines)); then
942 prune_lines=$(($linecount - $max_lines))
943 head -n $prune_lines "$HISTFILE" >> "$harchive" \
944 && sed -ie "1,${prune_lines}d" $HISTFILE
948 ############## work stuff #############
951 pushd /sdx/test/sandbox/;
965 ############# some other section
966 if [[ $- == *i* ]]; then
967 # commands to run when bash exits normally
972 # temporary variables to test colorization
973 # some copied from gentoo /etc/bash/bashrc,
975 # dircolors --print-database uses its own built-in database
976 # instead of using /etc/DIR_COLORS. Try to use the external file
977 # first to take advantage of user additions.
978 safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
980 [[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
981 [[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
982 [[ -z ${match_lhs} ]] \
983 && type -P dircolors >/dev/null \
984 && match_lhs=$(dircolors --print-database)
985 # test if our $TERM is in the TERM values in dircolor
986 [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
989 if ${use_color} && [[ $- == *i* ]]; then
991 if [[ $XTERM_VERSION == Cygwin* ]]; then
995 underl) echo -n $'\E[4m' ;;
996 bold) echo -n $'\E[1m' ;;
997 red) echo -n $'\E[31m' ;;
998 green) echo -n $'\E[32m' ;;
999 blue) echo -n $'\E[34m' ;;
1000 cyan) echo -n $'\E[36m' ;;
1001 yellow) echo -n $'\E[33m' ;;
1002 purple) echo -n $'\E[35m' ;;
1003 nocolor) echo -n $'\E(B\E[m' ;;
1012 underl) echo -n $(tput smul) ;;
1013 bold) echo -n $(tput bold) ;;
1014 red) echo -n $(tput setaf 1) ;;
1015 green) echo -n $(tput setaf 2) ;;
1016 blue) echo -n $(tput setaf 4) ;;
1017 cyan) echo -n $(tput setaf 6) ;;
1018 yellow) echo -n $(tput setaf 3) ;;
1019 purple) echo -n $(tput setaf 5) ;;
1020 nocolor) echo -n $(tput sgr0) ;; # no font attributes
1030 # Try to keep environment pollution down, EPA loves us.
1031 unset safe_term match_lhs use_color
1043 if [[ $- == *i* ]]; then
1044 # git branch/status prompt function
1045 if [[ $OS != Windows_NT ]]; then
1046 GIT_PS1_SHOWDIRTYSTATE=true
1048 # arch source location
1049 [[ -r /usr/share/git/git-prompt.sh ]] && source /usr/share/git/git-prompt.sh
1050 # fedora/debian source
1051 [[ -r /usr/share/git-core/contrib/completion/git-prompt.sh ]] && source /usr/share/git-core/contrib/completion/git-prompt.sh
1053 # in case we didn't source git-prompt.sh
1054 if ! declare -f __git_ps1 > /dev/null; then
1060 # this needs to come before next ps1 stuff
1061 # this stuff needs bash 4, feb 2009,
1062 # old enough to no longer condition on $BASH_VERSION anymore
1066 if [[ $- == *i* ]] && [[ ! $INSIDE_EMACS ]]; then
1068 bind -m vi-command B:shell-backward-word
1069 bind -m vi-command W:shell-forward-word
1072 if [[ $SSH_CLIENT ]]; then
1077 local return=$? # this MUST COME FIRST
1079 local ps_char ps_color
1081 history -a # save history
1082 history -n # read any new history
1083 if [[ ! $DESKTOP_SESSION == xmonad && $TERM == *(screen*|xterm*|rxvt*) ]]; then
1084 # from the screen man page
1085 if [[ $TERM == screen* ]]; then
1086 local title_escape="\033]..2;"
1088 local title_escape="\033]0;"
1090 echo -ne "$title_escape${PWD/#$HOME/~} $USER@$HOSTNAME\007"
1094 0) ps_color="$(get_term_color blue)"
1097 1) ps_color="$(get_term_color green)"
1098 ps_char="$return \\$"
1100 *) ps_color="$(get_term_color yellow)"
1101 ps_char="$return \\$"
1104 if [[ ! -O . ]]; then # not owner
1105 if [[ -w . ]]; then # writable
1106 ps_color="$(get_term_color bold red)"
1108 ps_color="$(get_term_color bold green)"
1111 PS1="${PS1%"${PS1#*[wW]}"}$(__git_ps1 ' (%s)') \[$ps_color\]$ps_char\[$(get_term_color nocolor)\] "
1113 PROMPT_COMMAND=prompt_command
1120 ###########################################
1121 # stuff that makes sense to be at the end #
1122 ###########################################
1123 if [[ "$SUDOD" ]]; then
1126 elif [[ -d /a ]] && [[ $PWD == $HOME ]] && [[ $- == *i* ]]; then
1135 # if someone exported $SOE, catch errors
1140 # I'd prefer to have system-wide, plus user ruby, due to bug in it
1141 # https://github.com/rubygems/rubygems/pull/1002
1142 # further problems: installing multi-user ruby and user ruby,
1143 # you don't get multi-user ruby when you sudo to root, unless its sudo -i.
1144 # There a third hybrid form, which passenger error suggested I use,
1145 # but it didn't actually work.
1147 # in cased I never need this
1148 # rvm for non-interactive shell: modified from https://rvm.io/rvm/basics
1149 #if [[ $(type -t rvm) == file && ! $(type -t ruby) ]]; then
1150 # source $(rvm 1.9.3 do rvm env --path)
1153 # based on warning from rvmsudo
1154 export rvmsudo_secure_path=1
1156 if [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
1157 source "/usr/local/rvm/scripts/rvm"
1159 # make our last exit code be 0