Mercurial > hg > cc > cirrus_home
changeset 157:cac9586291ad
no more gentoo,
split out functions into .bash_extras
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Mon, 04 Jul 2022 18:14:41 +0100 |
parents | ace590c2fdfc |
children | f5e2211b50bd |
files | .bash_extras .bashrc |
diffstat | 2 files changed, 122 insertions(+), 106 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.bash_extras Mon Jul 04 18:14:41 2022 +0100 @@ -0,0 +1,82 @@ +# Sourced by .bashrc + +cu () +{ + cvs update "$@" | egrep -v '^\?' +} + +lss () +{ + /bin/ls -l "$@" | sort -nr -k 5 +} + +ff () +{ + pat=$1; + shift; + find . -iname "*$pat*" $@ +} + +typecat () +{ + tt=$(type $1); + case $tt in + *\ is\ hashed\ *) + cat $(echo $tt | cut -f 4 -d ' ' | tr -d '()') + ;; + *\ is\ /*) + cat $(echo $tt | cut -f 3 -d ' ' | tr -d '()') + ;; + *) + type $1 + ;; + esac +} + +sus () +{ + sort "$@" | uniq -c | sort -k1nr,1 +} + +uz () +{ + igzip -dc "$@" +} + + +function typecat () +{ + tt=$(type $1) + case $tt in + *\ is\ hashed\ *) cat $(echo $tt | cut -f 4 -d ' ' | tr -d '()') ;; + *\ is\ /*) cat $(echo $tt | cut -f 3 -d ' ' | tr -d '()') ;; + *) type $1 ;; + esac +} + +function tot () +{ + awk '{sum+=$1} END {printf "%u\n",sum}' +} + +btot () +{ + python3 -c 'import sys +commas = False +if len(sys.argv)>1: + if sys.argv[1]=="-c": + commas = True +n=0 +for l in sys.stdin: + try: + n+=int(l) + except ValueError as e: + print(e,file=sys.stderr) +if commas: + print(f"{n:,}") +else: + print(n) +' "$@" +} + +export -f cu lss ff typecat sus uz tot btot
--- a/.bashrc Mon Jul 04 18:12:26 2022 +0100 +++ b/.bashrc Mon Jul 04 18:14:41 2022 +0100 @@ -1,124 +1,58 @@ # .bashrc -export G=${HOME}/gentoo # Uncomment the following line if you don't like systemctl's auto-paging feature: # export SYSTEMD_PAGER= -if [ $SHELL = "/bin/bash" ] -then - # Vanilla Cirrus login - # Source global definitions - if [ -f /etc/bashrc ]; then - . /etc/bashrc - fi - - if [ "$PS1" ]; then - PS1='\[\033[1m\]\h\[\033[0m\]<\!>: ' - echo "Vanilla bashrc" 1>&2 - # don't put duplicate lines or lines starting with space in the history. - # See bash(1) for more options - # export HISTCONTROL=ignoreboth [readonly on Cirrus :-[ - - # append to the history file, don't overwrite it - shopt -s histappend - - # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) - # export HISTSIZE=3000 [readonly on Cirrus :-[ - export HISTFILESIZE=6000 - export HISTIGNORE='[ ]*:&:[fb]g:exit' - fi - - module load gcc # assumed by Prefix - module load gnu-parallel - - export PYTHONPATH=$HOME/lib/python3.6/site-packages +# Source global definitions - PATH="/lustre/home/dc007/hst/lib/perl5/bin${PATH:+:${PATH}}"; export PATH; - PERL5LIB="/lustre/home/dc007/hst/lib/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB; - PERL_LOCAL_LIB_ROOT="/lustre/home/dc007/hst/lib/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT; - PERL_MB_OPT="--install_base \"/lustre/home/dc007/hst/lib/perl5\""; export PERL_MB_OPT; - PERL_MM_OPT="INSTALL_BASE=/lustre/home/dc007/hst/lib/perl5"; export PERL_MM_OPT; - - export ANT_HOME=$HOME/src/apache-ant-1.10.7 - export MAVEN_HOME=$HOME/src/apache-maven-3.6.3 - export JAVA_HOME=$HOME/lib/openjdk-8u252-b09 - export PATH=${PATH}:${ANT_HOME}/bin:${MAVEN_HOME}/bin - - EDITOR=emacs -else - # gentoo - if [ "$PS1" ]; then - echo "~/.bashrc inside gentoo" 1>&2 - PS1='\[\e[1;32m\]\h\[\e[0m\]<\!>: ' - # Source some global definitions? - - # These are readonly under Cirrus, so repeated here where they work1 - export HISTCONTROL=ignoreboth - export HISTSIZE=3000 - export HISTFILESIZE=6000 - shopt -s histappend - - if [ "$DISPLAY" ] - then - xrdb $HOME/.Xresources - fi - fi - EDITOR=xemacs +if [ -f /etc/bashrc ]; then + # This is protected against running twice... + . /etc/bashrc fi -# User specific aliases and functions -#module add gnu-parallel -#export N1=rli4n35 -#export N2=rli6n35 -#export NN="$N1 $N2" +. ~/.bash_extras -# Tools -function lss() { - /bin/ls -l "$@" | sort -nr -k 5,5 - } - -function sus() { - sort "$@" | uniq -c | sort -k1nr,1 +savehist () +{ + hc=$(history 1 | tr -d '\n' | cut -d ' ' -f 2); + if [ $((hc % ${HIST_FREQ-10})) = 0 ]; then + history -a; + fi } -function tot () +prompt () { - awk '{sum+=$1} END {printf "%u\n",sum}' + savehist + echo -ne '\033]0;'${HOSTNAME/-login/} ${PWD/$HOME/\~}'\007' } -btot () -{ - python3 -c 'import sys -commas = False -if len(sys.argv)>1: - if sys.argv[1]=="-c": - commas = True -n=0 -for l in sys.stdin: - try: - n+=int(l) - except ValueError as e: - print(e,file=sys.stderr) -if commas: - print(f"{n:,}") -else: - print(n) -' "$@" -} +if [ "$PS1" ]; then + PS1='\[\033[1m\]\h\[\033[0m\]<\!>: ' +# LD_LIBRARY_PATH=/home/dc007/dc007/hst/lib64 gdb >/dev/null 2>&1 <<EOF +# attach $$ +# call (int) unbind_variable("tt") +# detach +# quit +# EOF + USER_PROMPT_COMMAND=prompt + echo "Vanilla bashrc" 1>&2 + # don't put duplicate lines or lines starting with space in the history. + # See bash(1) for more options + # export HISTCONTROL=ignoreboth -function uz () { $G/usr/bin/igzip -dc "$@" ; } + # append to the history file, don't overwrite it + shopt -s histappend -function typecat () -{ - tt=$(type $1) - case $tt in - *\ is\ hashed\ *) cat $(echo $tt | cut -f 4 -d ' ' | tr -d '()') ;; - *\ is\ /*) cat $(echo $tt | cut -f 3 -d ' ' | tr -d '()') ;; - *) type $1 ;; - esac -} -#export HISTSIZE=3000 + # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) + # export HISTSIZE=3000 + export HISTFILESIZE=6000 + export HISTIGNORE='[ ]*:&:[fb]g:exit' +fi -PATH=$PATH:$HOME/.local/bin:$HOME/bin +EDITOR=emacs + +WSHARED=/work/dc007/dc007/shared -export PATH EDITOR PS1 G +PATH=$PATH:$HOME/.local/bin:$HOME/bin:$WSHARED/bin + +export PATH EDITOR PS1 WSHARED USER_PROMPT_COMMAND