X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=brc;h=30ee49a6680e4524dadfb4601acb02a899e1fce7;hb=ef571de225d48762aad38f9a5a3b28bbab654e39;hp=556c5ef04e743bb2208cc54dd7ae3d7cd1569cbe;hpb=6061d88c7d5beda3e974943eb8676f7c39d4ae9f;p=distro-setup diff --git a/brc b/brc index 556c5ef..30ee49a 100644 --- a/brc +++ b/brc @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # this gets sourced. shebang is just for file mode detection + # Use source ~/.bashrc instead of doing bash -l when running a script # so this can set extdebug and avoid the bash debugger. if [[ -s /a/bin/errhandle/err ]]; then @@ -12,24 +13,27 @@ elif [[ -s ~/.iank/err ]]; then source ~/.iank/err fi -t2() { - echo t2 - popd - grep sdf sdfd - echo wtf -} -t1() { - echo t1 - trap - t2 a b c -} +# In t8, it runs clear_console for login shells by default. I don't want +# my console cleared. And linux ttys get cleared without this. +if shopt login_shell >/dev/null && [[ -e ~/.bash_logout ]]; then + rm ~/.bash_logout +fi + +# for testing error catching: +# t2() { +# echo t2 +# grep sdf sdfd +# echo wtf +# } +# t1() { +# echo t1 +# t2 a b c +# } # * settings CDPATH=. -set -o pipefail - # 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 unalias -a @@ -156,28 +160,9 @@ if [[ $- == *i* ]]; then fi - -# history number. History expansion is good. -PS4='$LINENO+ ' -# history file size limit, set to unlimited. -# this needs to be different from the default because -# default HISTFILESIZE is 500 and could clobber our history -HISTFILESIZE= -# max commands 1 session can append/read from history -HISTSIZE=1000000 -# the time format display when doing the history command -# also, setting this makes the history file record time -# of each command as seconds from the epoch -HISTTIMEFORMAT="%Y-%m-%d %I:%M %p " -# consecutive duplicate lines dont go in history -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. dunno why, but just " *" does glob expansion, so use [ ] to avoid it. -HISTIGNORE='pass *:[ ]*:otp *:oathtool *' - export BC_LINE_LENGTH=0 +# ansible option export PROFILE_TASKS_TASK_OUTPUT_LIMIT=100 # note, if I use a machine I dont want files readable by all users, set @@ -333,7 +318,7 @@ cam() { ccat () { # config cat. see a config without extra lines. - grep '^\s*[^;[:space:]#]' "$@" + grep '^\s*[^;[:space:]#]' "$@" || [[ $? == 1 ]] } @@ -784,11 +769,11 @@ lower() { # make first letter of filenames lowercase. k() { # history search - grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | tail -n 80; + grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | tail -n 80 || [[ $? == 1 ]]; } ks() { # history search - grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | uniq; + grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | uniq || [[ $? == 1 ]]; } @@ -828,7 +813,7 @@ pkx() { # package extract c $(mktemp -d) pkg=$1 # shellcheck disable=SC2012 - cached=$(ls -t /var/cache/apt/archives/$pkg* | tail -n1 2>/dev/null) + cached=$(ls -t /var/cache/apt/archives/$pkg* | tail -n1 2>/dev/null) ||: if [[ $cached ]]; then cp $cached . else @@ -870,7 +855,7 @@ grep ps and output in a nice format" # final grep is because some commands tend to have a lot of trailing spaces y=$(echo "$x" | grep -iP "$@" | grep -o '.*[^ ]') ||: if [[ $y ]]; then - echo "$x" | head -n 1 + echo "$x" | head -n 1 || [[ $? == 141 ]] echo "$y" fi } @@ -904,7 +889,9 @@ q() { # start / launch a program in the backround and redir output to null # shellcheck disable=SC2120 r() { - history -a # save history + if [[ $HISTFILE ]]; then + history -a # save history + fi trap ERR # this avoids a segfault exit ${1:0} # i had this redir, not sure why @@ -1284,7 +1271,16 @@ if [[ $- == *i* ]]; then local ps_char ps_color unset IFS - history -a # save history + if [[ $HISTFILE ]]; then + history -a # save history + fi + + if [[ $jr_pid ]]; then + if [[ -e /proc/$jr_pid ]]; then + kill $jr_pid + fi + unset jr_pid + fi case $return in 0) ps_color="$term_purple" @@ -1350,6 +1346,14 @@ unset IFS # shellcheck disable=SC1090 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* +# I had this idea to start a bash shell which would run an initial +# command passed through this env variable, then continue on +# interactively. But the use case I had in mind went away. +# +# if [[ $MY_INIT_CMD ]]; then +# "${MY_INIT_CMD[@]}" +# unset MY_INIT_CMD +# fi # ensure no bad programs appending to this file will have an affect return 0