X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=bashrc;h=fff96ac3cbaf2f3d9a28b64a1c476e1a8a4cf489;hb=d9930e7823c007964a023880587f23db98754eb8;hp=178504ec8ce9b7254693a5b5a015b94f9906c1a6;hpb=784249066ea9199db8b8a31778decc8738c7ef51;p=scripts.git diff --git a/bashrc b/bashrc index 178504e..fff96ac 100644 --- a/bashrc +++ b/bashrc @@ -23,11 +23,11 @@ PRIVATE_BASHRC="${HOME}/private/bashrc.perso" # If the MANPATH is not set, set it -[ "${MANPATH}" ] || MANPATH=$(manpath) +[[ "${MANPATH}" ]] || MANPATH=$(manpath) # If the private bashrc exists, execute it -[ -f "${PRIVATE_BASHRC}" ] && source "${PRIVATE_BASHRC}" +[[ -f "${PRIVATE_BASHRC}" ]] && source "${PRIVATE_BASHRC}" # !!! THIS HAS TO BE HERE EVEN IN THE NON-INTERACTIVE PART OR YOU WILL # LOSE YOU PREVIOUS HISTORY !!! @@ -52,7 +52,9 @@ shopt -s histappend # Remove the annoying beeps in console -setterm -blength 0 +# setterm -blength 0 + +# || setterm --blength 0 # Seriously? ###################################################################### ## The interactive part @@ -161,14 +163,16 @@ function latexdiff () { wdiff -n \ -w $'\033[30;41m' -x $'\033[0m' \ -y $'\033[30;42m' -z $'\033[0m' \ - $* + "$@" } # Looks for the most recent .log and pdflatex + bibtex the # corresponding tex file function rl () { - RECENT_LOG=$(ls -t $(find -maxdepth 1 -name "*.log" -type f) | head -1) + # RECENT_LOG=$(ls -t $(find -maxdepth 1 -name "*.log" -type f) | head -1) + + RECENT_LOG=$(ls -t *.log | head -1) if [[ ${RECENT_LOG} ]]; then FILEBASE="${RECENT_LOG/.log/}" @@ -238,10 +242,11 @@ function bak () { done } -# Password generator +# A password generator -function pwgen () { +function genpw () { tr -dc A-Za-z0-9 < /dev/urandom | head -c16 + # tr -dc [:graph:] < /dev/urandom | head -c16 echo } @@ -364,7 +369,7 @@ function pho () { function dt () { echo "Local: $(date)" if [[ ${TZ} ]]; then - unset TZ + local TZ=$(cat /etc/timezone) echo "Home: $(date)" fi } @@ -517,8 +522,8 @@ KEPT_COMMANDS=${HOME}/.kept_bash_commands function keep () { if [[ ${KEPT_COMMANDS} ]]; then TOKEEP=$(mktemp /tmp/keep.XXXXXX) - if [[ "$*" ]]; then - echo "$*" > ${TOKEEP} + if [[ "$@" ]]; then + echo "$@" > ${TOKEEP} else selector -b -i -d -l ${HISTSIZE} -o "${TOKEEP}" <(history) fi @@ -540,12 +545,12 @@ function keep () { # I sometime burn CDs and DVDs function burn () { - DEVICE="/dev/cdrw1" + [[ "${DEV_BURNER}" ]] || DEV_BURNER="/dev/sr0" if [[ ! "$1" ]]; then echo "burn " >&2 elif [[ -f "$1" ]]; then if [[ $(file "$1" | \grep -E 'ISO 9660|UDF filesystem data') ]]; then - wodim -eject -v dev=${DEVICE} "$1" + wodim -eject -v dev=${DEV_BURNER} "$1" else echo "Do not know what to do with $1" >&2 fi @@ -554,7 +559,7 @@ function burn () { echo "Using ${TMP_ROOT} as temporary directory." TMP=$(mktemp ${TMP_ROOT}/cdimage.XXXXXX) && \ genisoimage -input-charset iso8859-1 -r -o ${TMP} "$1" && \ - wodim -eject -v dev=${DEVICE} ${TMP} + wodim -eject -v dev=${DEV_BURNER} ${TMP} rm -f ${TMP} else echo "Can not find $1" >&2 @@ -613,7 +618,7 @@ function ripdvd () { mkdir -p ${HOME}/dvds cd ${HOME}/dvds - time dvdbackup -i ${DVD_DEVICE} -v -M $* && eject + time dvdbackup -i ${DVD_DEVICE} -v -M "$@" && eject } alias ripcd=abcde @@ -623,7 +628,13 @@ alias ripcd=abcde function mksmall () { - [[ "${PARAMS}" ]] || PARAMS="-geometry 800x600" + if [[ "$1" == "--params" ]]; then + shift + PARAMS="$1" + shift + fi + + [[ "${PARAMS}" ]] || PARAMS="-geometry 1280x1024" # Auto-orient does not seem to work at all, hence the ugly hack # with exif below @@ -710,25 +721,19 @@ else [[ "${IDENT}" ]] && IDENT="${IDENT}:" - # If we are root, show that in red - if [[ ${USER} == "root" ]]; then + # If we are root, show that in red PS1="\[${VT_RED_BG}${VT_WHITE_FG}\]${IDENT}\w\[${VT_RESET}\] " else - PS1="\[${VT_WHITE_BG}${VT_BLACK_FG}\]${IDENT}\w\[${VT_RESET}\] " + if [[ $(\grep QEMU /proc/cpuinfo) ]]; then + # If we are in a qemu virtual machine, in yellow + PS1="\[${VT_YELLOW_BG}${VT_BLACK_FG}\]${IDENT}\w\[${VT_RESET}\] " + else + # Otherwise in white + PS1="\[${VT_WHITE_BG}${VT_BLACK_FG}\]${IDENT}\w\[${VT_RESET}\] " + fi fi - # In an xterm, show the hostname and path in the title bar, highlight - # the prompt - - # [[ "${TERMS_WITH_BAR}" ]] || TERMS_WITH_BAR="^xterm|screen$" - - # if [[ "${TERM}" =~ "${TERMS_WITH_BAR}" ]]; then - # PS1="\[${VT_SET_TITLE}shell@\h (\w)${VT_END_TITLE}${VT_WHITE_BG}\]${IDENT}\w\[${VT_RESET}\] " - # else - # PS1="\[${VT_WHITE_BG}\]${IDENT}\w\[${VT_RESET}\] " - # fi - fi ###################################################################### @@ -756,7 +761,7 @@ function keep_local_history () { PS1="\[${VT_WHITE_BG}\]\${LOCAL_HISTORY_HINT}\[${VT_RESET}\]${PS1}" ###################################################################### -# Switch off the history +# Show the history path if it is unusual function histfile_cue () { if [[ ! "${HISTFILE}" == "${HOME}/.bash_history" ]]; then @@ -787,6 +792,8 @@ alias finddup='finddup -p' # # git clone http://fleuret.org/git/selector/ +export SELECTOR_CD_HISTORY_SIZE=10000 + source bash-selector.sh --hist --cd ###################################################################### @@ -811,11 +818,11 @@ function selector-printer () { # the current directory function lsn () { - LSN_MEMORY=".lsn-state" + [[ "${LSN_STATE_FILE}" ]] || LSN_STATE_FILE=".lsn-state" if [[ $1 == "--mem" ]] || [[ "$1" == "-m" ]]; then - \ls -pa | sort > ${LSN_MEMORY} + \ls -pa | sort > "${LSN_STATE_FILE}" echo "State updated." >&2 elif [[ $1 == "+" ]]; then @@ -823,32 +830,49 @@ function lsn () { shift TMP=$(mktemp /tmp/lsn.XXXXXX) - \ls -d $* > ${TMP} - cat ${LSN_MEMORY} >> ${TMP} - sort -u ${TMP} > ${LSN_MEMORY} + \ls -d "$@" > ${TMP} + cat "${LSN_STATE_FILE}" >> ${TMP} + sort ${TMP} | uniq -u > "${LSN_STATE_FILE}" \rm ${TMP} elif [[ "$1" ]]; then + cat >&2 < ...] - echo "lsn [--mem|-m] [+ ...]" >&2 - return 1 +Where + + --help|-h + prints this help + + --mem|-m + stores the current state of the directory + + + [ ...] + switches the presence/absence of the indicated files in the + stored state + +EOF + if [[ ! "$1" == "-h" ]] && [[ ! "$1" == "--help" ]]; then + echo >&2 "Unknown option \`\`$1''." + return 1 + fi else - if [[ -f ${LSN_MEMORY} ]]; then + if [[ -f "${LSN_STATE_FILE}" ]]; then TMP=$(mktemp /tmp/lsn.XXXXXX) \ls -pa | sort > ${TMP} - if diff > /dev/null ${TMP} ${LSN_MEMORY}; then - echo "${VT_GREEN_FG}${VT_BOLD}No change (since $(date +"%b %d, %Y" -r ${LSN_MEMORY}))${VT_RESET}" + if diff > /dev/null ${TMP} "${LSN_STATE_FILE}"; then + echo "${VT_GREEN_FG}${VT_BOLD}No change (since $(date +"%b %d, %Y" -r "${LSN_STATE_FILE}"))${VT_RESET}" else - \comm -1 -3 ${LSN_MEMORY} ${TMP} - \comm -2 -3 ${LSN_MEMORY} ${TMP} | while read line; do + \comm -1 -3 "${LSN_STATE_FILE}" ${TMP} + \comm -2 -3 "${LSN_STATE_FILE}" ${TMP} | while read line; do echo "${VT_RED_FG}${VT_BOLD}${line}${VT_RESET} (missing)" done fi \rm ${TMP} else - echo "No lsn state here." >&2 + echo "${VT_RED_FG}${VT_BOLD}No lsn state here.${VT_RESET}" >&2 return 1 fi @@ -858,6 +882,9 @@ function lsn () { ###################################################################### function prompt_command () { + # if [[ $(umask) != 0022 ]]; then + # echo "Umask changed to $(umask)" + # fi # save the history after every command to avoid loosing some when # multiple shells are open history -a @@ -875,8 +902,6 @@ PROMPT_COMMAND="prompt_command" # Displaying the timezone if it is set -if [[ ${TZ} ]]; then - echo "${VT_BOLD}${VT_GREEN_FG}Time zone is ${TZ}.${VT_RESET}" -fi +[[ ${TZ} ]] && echo "${VT_BLUE_FG}Time zone is ${TZ}.${VT_RESET}" ######################################################################