X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=scripts.git;a=blobdiff_plain;f=bashrc;h=93b9e5642a444eeeec88d0a3b449efc7b26c3920;hp=9ee087b76991f57b08ff88c811ec926aec96be50;hb=HEAD;hpb=b0719544d007de898f71c628225db267884b02d7 diff --git a/bashrc b/bashrc index 9ee087b..93b9e56 100644 --- a/bashrc +++ b/bashrc @@ -1,5 +1,8 @@ # -*-Shell-script-*- +# PS4='+ $(date "+%s.%N")\011 ' +# set -x + ######################################################################### # This program is free software: you can redistribute it and/or modify # # it under the terms of the version 3 of the GNU General Public License # @@ -25,6 +28,9 @@ PRIVATE_BASHRC="${HOME}/private/bashrc.perso" [[ "${MANPATH}" ]] || MANPATH=$(manpath) +export EDITOR='emacs -nw' +export GIT_EDITOR=${EDITOR} + # If the private bashrc exists, execute it [[ -f "${PRIVATE_BASHRC}" ]] && source "${PRIVATE_BASHRC}" @@ -43,11 +49,17 @@ export HISTIGNORE="${HISTIGNORE}:&:[ ]*" export HISTTIMEFORMAT="" shopt -s histappend +shopt -s autocd # I realized that most of my settings are meaningful only in # interactive mode. This should maybe be done more properly through # using different .bash_profile and .bash_login +###################################################################### + +# added by Miniconda3 installer +export PATH="${HOME}/conda/bin:$PATH" + [ ${TERM} == "dumb" ] || [[ ! -t 0 ]] && return # Remove the annoying beeps in console @@ -120,8 +132,23 @@ alias find='ionice -c3 find' alias pd=pushd alias val='valgrind --leak-check=full --show-reachable=yes --db-attach=yes ' -alias s='screen -d -R -U && clear' +alias s='screen -d -R default -U && clear' alias p='feh --force-aliasing -d --full-screen --auto-zoom' +alias gp=gnuplot + +function ext () { + find . -maxdepth 1 -type f | \grep \. | sed -e 's/^.*\.\([^/.]*\)$/\1/' +} + +# function catscan () { + # convert signal-attachment-2020-06-01-192843.jpeg signal-attachment-2020-06-01-192829.jpeg -quality 25 -sigmoidal-contrast 10,45% -page a4 scan.pdf +# } + +function trash-later () { + dir=${HOME}/misc/trash-later/remove-after-$(date --date='+3 months' +%Y-%b-%d) + mkdir -p "${dir}" + pushd "${dir}" +} function nh () { export HISTFILE=/dev/null @@ -166,9 +193,6 @@ else alias l='ls -p -I "*~" -I "*.o"' fi -export EDITOR=emacsclient -export GIT_EDITOR=${EDITOR} - ###################################################################### # Ignored extensions when completing @@ -205,7 +229,8 @@ function rl () { then if [[ "$1" == "-v" ]] || [[ "$1" == "--view" ]] then - xpdf "${FILEBASE}.pdf" + # xpdf "${FILEBASE}.pdf" + zathura "${FILEBASE}.pdf" elif [[ "$1" == "-p" ]] || [[ "$1" == "--print" ]] then lpr "${FILEBASE}.pdf" @@ -314,7 +339,18 @@ function scan () { # A password generator function genpw () { - tr -dc A-Za-z0-9 < /dev/urandom | head -c16 + if [[ "$1" == "-e" ]] + then + PW=$(tr -dc A-Z0-9 < /dev/urandom | head -c6) + shift + else + PW=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c16) + fi + if [[ ! "$1" == "-s" ]] + then + echo "$(date) ${PW}" >> ${HOME}/private/genpw.log + fi + echo ${PW} # tr -dc [:graph:] < /dev/urandom | head -c16 echo } @@ -363,7 +399,7 @@ function cap () { then name=$2 else - name="capture-$(date +%s).png" + name="capture-$(date +%Y%m%d-%H%M%S).png" fi if [[ "$1" ]] @@ -375,7 +411,7 @@ function cap () { fi echo "Please click on the window to capture." - xwd | convert - ${name} + xwd | convert xwd:- ${name} \ls -l ${name} } @@ -411,7 +447,32 @@ alias t='cd /tmp' alias a='cd /tmp/at' function trash () { - TRASH=$(date +/tmp/trash-${USER}-%Y-%b-%d-%Hh) + + [[ "${TRASH_LATER_ROOT}" ]] || TRASH_LATER_ROOT="${HOME}/.trash" + + if [[ "$1" == "--" ]] + then + shift + elif [[ "$1" == "-l" ]] + then + shift + echo "Trashin in 3 months" + TRASH_DIR="${TRASH_LATER_ROOT}/remove-after-$(date --date='+3 months' +%Y-%b-%d)" + mkdir -p "${TRASH_DIR}" + else + TRASH_DIR=$(date +/tmp/trash-${USER}-%Y-%b-%d-%Hh) + LINK=/tmp/trash + mkdir -p ${TRASH_DIR} + [[ -h ${LINK} ]] && \rm ${LINK} + [[ ! -f ${LINK} ]] && ln -s ${TRASH_DIR} ${LINK} + fi + + mv "$@" "${TRASH_DIR}" + echo "Trashed $@" +} + +function trashlatex () { + TRASH=$(date +/tmp/trash-latex-${USER}-%Y-%b-%d-%Hh) LINK=/tmp/trash mkdir -p ${TRASH} @@ -420,8 +481,11 @@ function trash () { [[ ! -f ${LINK} ]] && ln -s ${TRASH} ${LINK} - mv "$@" ${TRASH} - echo "Trashed $@" + mv -v \ + *.log *.pdf *.aux *.nav *.pdfpc *.snm *.toc *.out \ + *.bbl *.blg \ + *.*.table *.*.gnuplot \ + ${TRASH} } ###################################################################### @@ -456,13 +520,7 @@ function dt () { } ###################################################################### -## ifup / ifdown with sudo and memorization of the network - -## When invoked without an argument netup uses the same argument as -## the previous time - -## When invoked without an argument netdown removes the last interface -## which was netuped +## ifup / ifdown with sudo [ ${NETUP_HISTORY} ] || NETUP_HISTORY="${HOME}/.netup_history" @@ -490,7 +548,7 @@ function netup () { return 0 fi - if \ifconfig -s | grep -q -v ^'(Iface|lo) ' + if \ifconfig -s | grep -q -v ^'(Iface|lo|docker[0-9]) ' then echo "There is/are already interface(s) up." >&2 return 1 @@ -761,7 +819,7 @@ function ripdvd () { return 1 fi - echo "Attemptin to rip from ${DVD_DEVICE}." + echo "Attempting to rip from ${DVD_DEVICE}." mkdir -p ${HOME}/dvds @@ -850,6 +908,20 @@ function mvtoconfig () { fi } + +###################################################################### +# git prompt + +if which > /dev/null git +then + + parse_git_branch() { + git 2>/dev/null rev-parse --abbrev-ref HEAD | sed -e 's/^\(.*\)$/(\1) /' + } + + export PS_GIT="${VT_GREEN_FG}\$(parse_git_branch)" +fi + ###################################################################### # The complex prompt policy @@ -880,6 +952,8 @@ else [[ "${IDENT}" ]] && IDENT="${IDENT}:" + # IDENT="${PS_GIT}${VT_BLACK_FG}${IDENT}" + if [[ ${USER} == "root" ]] then # If we are root, show that in red @@ -897,7 +971,7 @@ else fi -PS1="${PSCUE}${PS1}" +#PS1="${PSCUE}${PS1}" ###################################################################### # This implements a local history. If we are in a directory containing @@ -1065,7 +1139,7 @@ function prompt_command () { # multiple shells are open history -a # load the saved history - history -n + # history -n # and the local histories system defined above keep_local_history # and the history cue @@ -1081,3 +1155,5 @@ PROMPT_COMMAND="prompt_command" [[ ${TZ} ]] && echo "${VT_BLUE_FG}Time zone is ${TZ}.${VT_RESET}" ###################################################################### + +source /usr/share/bash-completion/bash_completion