3 # PS4='+ $(date "+%s.%N")\011 '
6 #########################################################################
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the version 3 of the GNU General Public License #
9 # as published by the Free Software Foundation. #
11 # This program is distributed in the hope that it will be useful, but #
12 # WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
14 # General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # Written by and Copyright (C) Francois Fleuret #
20 # Contact <francois@fleuret.org> for comments & bug reports #
21 #########################################################################
23 # The site-specific and confidential settings are in another file
25 PRIVATE_BASHRC="${HOME}/private/bashrc.perso"
27 # If the MANPATH is not set, set it
29 [[ "${MANPATH}" ]] || MANPATH=$(manpath)
31 export EDITOR='emacs -nw'
32 export GIT_EDITOR=${EDITOR}
34 # If the private bashrc exists, execute it
36 [[ -f "${PRIVATE_BASHRC}" ]] && source "${PRIVATE_BASHRC}"
38 # !!! THIS HAS TO BE HERE EVEN IN THE NON-INTERACTIVE PART OR YOU WILL
39 # LOSE YOU PREVIOUS HISTORY !!!
41 export HISTFILESIZE=20000
42 export HISTSIZE=${HISTFILESIZE}
44 export HISTIGNORE="${HISTIGNORE}:&:[ ]*"
46 # I want to save the command time, but I do not want to see it in
49 export HISTTIMEFORMAT=""
54 # I realized that most of my settings are meaningful only in
55 # interactive mode. This should maybe be done more properly through
56 # using different .bash_profile and .bash_login
58 ######################################################################
60 # added by Miniconda3 installer
61 export PATH="/home/fleuret/conda/bin:$PATH"
63 [ ${TERM} == "dumb" ] || [[ ! -t 0 ]] && return
65 # Remove the annoying beeps in console
69 # || setterm --blength 0 # Seriously?
71 ######################################################################
72 ## The interactive part
74 export VT_RESET=$'\e[0m'
75 export VT_BOLD=$'\e[1m'
76 export VT_UNDERLINE=$'\e[4m'
77 export VT_BLINK=$'\e[5m'
79 export VT_SET_TITLE=$'\e]0;'
80 export VT_END_TITLE=$'\007'
82 export VT_BLACK_FG=$'\e[30m'
83 export VT_RED_FG=$'\e[31m'
84 export VT_GREEN_FG=$'\e[32m'
85 export VT_YELLOW_FG=$'\e[33m'
86 export VT_BLUE_FG=$'\e[34m'
87 export VT_MAGENTA_FG=$'\e[35m'
88 export VT_CYAN_FG=$'\e[36m'
89 export VT_WHITE_FG=$'\e[37m'
91 export VT_BLACK_BG=$'\e[40m'
92 export VT_RED_BG=$'\e[41m'
93 export VT_GREEN_BG=$'\e[42m'
94 export VT_YELLOW_BG=$'\e[43m'
95 export VT_BLUE_BG=$'\e[44m'
96 export VT_MAGENTA_BG=$'\e[45m'
97 export VT_CYAN_BG=$'\e[46m'
98 export VT_WHITE_BG=$'\e[47m'
100 # Colorize man pages!
102 export LESS_TERMCAP_us=${VT_GREEN_FG}
103 export LESS_TERMCAP_ue=${VT_RESET}
104 export LESS_TERMCAP_md=${VT_BLUE_FG}${VT_BOLD}
105 export LESS_TERMCAP_me=${VT_RESET}
107 # I do not like to clutter my home with history files
109 export LESSHISTFILE=/dev/null
111 # export LESS_TERMCAP_md=$'\e[1;34;40m'
113 # This prevents ^S from freezing the shell
123 alias chmod='chmod -c'
129 # alias df='df -hT --sync'
130 alias grep='grep -i -E --color=auto'
131 alias find='ionice -c3 find'
133 alias val='valgrind --leak-check=full --show-reachable=yes --db-attach=yes '
135 alias s='screen -d -R default -U && clear'
136 alias p='feh --force-aliasing -d --full-screen --auto-zoom'
140 find . -maxdepth 1 -type f | \grep \. | sed -e 's/^.*\.\([^/.]*\)$/\1/'
144 dir=${HOME}/misc/use-by-$(date --date='+3 months' +%Y-%b-%d)
150 export HISTFILE=/dev/null
154 function select-tz () {
155 # Select a value for TZ
156 TMP=$(mktemp /tmp/select-tz.XXXXXX)
157 selector -o "${TMP}" <(grep -v ^# /usr/share/zoneinfo/zone.tab | awk '{print $3}' | sort -u)
163 if [[ $1 ]] && which winshepherd.sh
165 play -q ~/local/sounds/deskbell.wav &
167 winshepherd.sh message green "$1"
169 play -q ~/local/sounds/deskbell.wav
173 alias impressive="impressive -s -D 1000 -t Crossfade -T 100"
175 if [[ -e "${HOME}/.dircolors" ]]
177 eval $(dircolors "${HOME}/.dircolors")
178 alias ls='ls -p --group-directories-first --color'
179 alias lt='ls -p --color -gohtr --time-style="+%Y %b %d %H:%M"'
180 alias ll='ls -p --color -goh --time-style="+%Y %b %d %H:%M"'
181 alias lll='ls -p --color -lth'
182 alias l='ls -p --color -I "*~" -I "*.o"'
185 alias ls='ls -p --group-directories-first'
186 alias lt='ls -p -gohtr --time-style="+%Y %b %d %H:%M"'
187 alias ll='ls -p -goh --time-style="+%Y %b %d %H:%M"'
188 alias lll='ls -p -lth'
189 alias l='ls -p -I "*~" -I "*.o"'
192 ######################################################################
193 # Ignored extensions when completing
195 # export FIGNORE="CVS"
197 function latexdiff () {
199 -w $'\033[30;41m' -x $'\033[0m' \
200 -y $'\033[30;42m' -z $'\033[0m' \
204 # Looks for the most recent .log and pdflatex + bibtex the
205 # corresponding tex file
208 # RECENT_LOG=$(ls -t $(find -maxdepth 1 -name "*.log" -type f) | head -1)
210 RECENT_LOG=$(ls -t *.log | head -1)
212 if [[ ${RECENT_LOG} ]]
214 FILEBASE="${RECENT_LOG/.log/}"
216 if [[ -f "${FILEBASE}.tex" ]]
219 pdflatex --shell-escape "${FILEBASE}"
221 pdflatex --shell-escape "${FILEBASE}"
222 pdflatex --shell-escape "${FILEBASE}"
226 if [[ "$1" == "-v" ]] || [[ "$1" == "--view" ]]
228 # xpdf "${FILEBASE}.pdf"
229 zathura "${FILEBASE}.pdf"
230 elif [[ "$1" == "-p" ]] || [[ "$1" == "--print" ]]
232 lpr "${FILEBASE}.pdf"
234 echo "Usage: rl [-v|--view] [-p|--print]" >&2
235 echo "Unknown option $1" >&2
242 echo "Can not find a tex file corresponding to the most recent log (${RECENT_LOG/.log/})." >&2
248 echo "Can not find a recent log." >&2
254 ######################################################################
257 # http://www.reddit.com/r/linux/comments/2cgu5k/a_handy_little_script_for_interacting_with_your/
259 if [[ -t 0 ]] && [[ -z "$1" ]]
261 # output contents of clipboard
262 xclip -out -selection clipboard || exit 1
265 # copy file contents to clipboard
266 xclip -in -selection clipboard < "$1" || exit 1
268 # copy stdin to clipboard
269 xclip -in -selection clipboard <&0 || exit 1
273 # Find a file whose name contains a substring
278 find "$@" -name "*${name}*";
292 while [[ -f "${HOME}/scan-${n}.jpg" ]]
299 if [[ "$1" == "color" ]]
301 OPTS+=" --mode Color"
302 elif [[ "$1" == "gray" ]]
305 elif [[ "$1" == "a4crop" ]]
307 OPTS+=" -l 5 -t 0 -x 200 -y 300"
308 elif [[ "$1" == "help" ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]
310 echo "$0 [color|gray] [a4crop]" && return 0
312 echo "Unknown argument \`$1'"
318 echo "** Scanning to ${HOME}/scan-${n}.jpg"
321 SCANNER=$(scanimage -L | grep "Canon LiDE 60" | sed -e "s/^.*\`\(.*\)'.*$/\1/")
323 scanimage -d ${SCANNER} \
330 convert -rotate 180 - "${HOME}/scan-${n}.jpg"
335 # A password generator
338 if [[ "$1" == "-e" ]]
340 PW=$(tr -dc A-Z0-9 < /dev/urandom | head -c6)
343 PW=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c16)
345 if [[ ! "$1" == "-s" ]]
347 echo "$(date) ${PW}" >> ${HOME}/private/genpw.log
350 # tr -dc [:graph:] < /dev/urandom | head -c16
356 [[ "$1" ]] || ( echo "Universal unarchive: ua <file> [<file> ...]" >&2 && return 1)
362 *.tgz|*.tar.gz|*.tbz|*.tar.bz2)
375 echo "Unknown file extension $1"
384 # Create a dir and cd there
391 # Capture the screen in a dated png
398 name="capture-$(date +%Y%m%d-%H%M%S).png"
403 echo "Waiting $1 s and saving to ${name}."
406 echo "Saving to ${name}."
409 echo "Please click on the window to capture."
410 xwd | convert xwd:- ${name}
414 # Create and CD in a /tmp/tmp.XXXXXX directory. With the '-'
415 # arguments, do not create one and CD in the most recent instead
422 cd $(\ls -td /tmp/tmp.?????? | head -1)
424 echo "USAGE: cdt [-]" >&2
428 dir=$(mktemp -d /tmp/tmp.XXXXXX)
434 if [[ ! -a ${link} ]]
447 [[ "${TRASH_ROOT}" ]] || TRASH_ROOT="${HOME}/.trash"
449 if [[ "$1" == "--" ]]
452 elif [[ "$1" == "-t" ]]
455 TRASH_DIR="${TRASH_ROOT}"
456 mkdir -p "${TRASH_DIR}"
458 TRASH_DIR=$(date +/tmp/trash-${USER}-%Y-%b-%d-%Hh)
460 mkdir -p ${TRASH_DIR}
461 [[ -h ${LINK} ]] && \rm ${LINK}
462 [[ ! -f ${LINK} ]] && ln -s ${TRASH_DIR} ${LINK}
465 mv "$@" "${TRASH_DIR}"
469 function trashlatex () {
470 TRASH=$(date +/tmp/trash-latex-${USER}-%Y-%b-%d-%Hh)
475 [[ -h ${LINK} ]] && \rm ${LINK}
477 [[ ! -f ${LINK} ]] && ln -s ${TRASH} ${LINK}
480 *.log *.pdf *.aux *.nav *.pdfpc *.snm *.toc *.out \
482 *.*.table *.*.gnuplot \
486 ######################################################################
487 ## A version of pho which stores the image numbers in environment
491 TEMP=$(mktemp /tmp/pho.XXXXXXX)
492 $(which pho) "$@" | tee ${TEMP}
493 PHO_NOTE_1=$(grep ^"Note 1: " ${TEMP} | sed -e "s/^[^:]*: //")
494 PHO_NOTE_2=$(grep ^"Note 2: " ${TEMP} | sed -e "s/^[^:]*: //")
495 PHO_NOTE_3=$(grep ^"Note 3: " ${TEMP} | sed -e "s/^[^:]*: //")
496 PHO_NOTE_R90=$(grep ^"Rotate 90 \(CW\): " ${TEMP} | sed -e "s/^[^:]*: //")
497 PHO_NOTE_R180=$(grep ^"Rotate 180: " ${TEMP} | sed -e "s/^[^:]*: //")
498 PHO_NOTE_R270=$(grep ^"Rotate -90 \(CCW\): " ${TEMP} | sed -e "s/^[^:]*: //")
499 [[ "${PHO_NOTE_1}" ]] || unset PHO_NOTE_1
500 [[ "${PHO_NOTE_2}" ]] || unset PHO_NOTE_2
501 [[ "${PHO_NOTE_3}" ]] || unset PHO_NOTE_3
502 [[ "${PHO_NOTE_R90}" ]] || unset PHO_NOTE_R90
503 [[ "${PHO_NOTE_R180}" ]] || unset PHO_NOTE_R180
504 [[ "${PHO_NOTE_R270}" ]] || unset PHO_NOTE_R270
508 ######################################################################
509 ## A version of date that shows the time at home if TZ is set
512 echo "Local - $(date)"
514 echo "Home - $(date)"
517 ######################################################################
518 ## ifup / ifdown with sudo
520 [ ${NETUP_HISTORY} ] || NETUP_HISTORY="${HOME}/.netup_history"
525 [[ "${WIFI_INTERFACE}" ]] || WIFI_INTERFACE=wlan0
527 if [[ "$1" == "--scan" ]]
529 if ifconfig -s | grep -v -q ${WIFI_INTERFACE}
531 sudo ifconfig ${WIFI_INTERFACE} up
535 sudo iwlist ${WIFI_INTERFACE} scan | \grep -E 'ESS|Quali|Encry' | sed -e 's/^[ \t]*//'
537 if [[ ${upped_wifi} ]]
539 sudo ifconfig ${WIFI_INTERFACE} down
546 if \ifconfig -s | grep -q -v ^'(Iface|lo) '
548 echo "There is/are already interface(s) up." >&2
552 if \ps h -C dhclient | grep -q .
554 echo "There is already a dhcp client running." >&2
558 if \ps h -C wpa_supplicant | grep -q .
560 echo "There is already a wpa_supplicant running." >&2
564 if [[ ! "$@" ]] && [[ -s ${NETUP_HISTORY} ]]
566 echo "netup <interface>" >&2
568 # # If we have no argument and there is a .netup_history, use it
569 # ARGS=$(cat ${NETUP_HISTORY})
571 # Otherwise uses the given arguments, and store them
573 echo ${ARGS} > ${NETUP_HISTORY}
576 if [[ "${PRIVATE_INTERFACE_DEFINITION}" ]]
578 ARGS="-i ${PRIVATE_INTERFACE_DEFINITION} ${ARGS}"
581 echo "Executing ${VT_GREEN_FG}[sudo ifup ${ARGS}]${VT_RESET}"
584 # Ugly hack to remove the dsl modem dns server when we add
585 # explicitely a dns in the /etc/network/interfaces
587 REMOVE_LOCAL_DNS=/usr/local/bin/remove-local-dns.sh
588 # REMOVE_LOCAL_DNS=${HOME}/sources/scripts/remove-local-dns.sh
590 if [[ -x ${REMOVE_LOCAL_DNS} ]]
592 echo "Executing ${VT_GREEN_FG}[sudo ${REMOVE_LOCAL_DNS} 192.168]${VT_RESET}"
593 sudo ${REMOVE_LOCAL_DNS} 192.168
597 function netdown () {
598 if [[ ! "$@" ]] && [[ -s ${NETUP_HISTORY} ]]
600 # If there are no arguments and there is a .netup_history, get the
602 ARGS=$(tail -1 ${NETUP_HISTORY} | sed -e "s/=.*$//")
604 # Otherwise, use the standard ifdown
608 [[ "${PRIVATE_INTERFACE_DEFINITION}" ]] && ARGS="-i ${PRIVATE_INTERFACE_DEFINITION} ${ARGS}"
610 echo "Executing sudo ${VT_GREEN_FG}[ifdown ${ARGS}]${VT_RESET}"
613 # if [[ $(\ps -C dhclient | tail -n +2) ]]
615 # echo "There is still a dhcp client running." >&2
619 # if [[ $(\ps -C wpa_supplicant | tail -n +2) ]]
621 # echo "There is still a wpa_supplicant running." >&2
626 function checkgw () {
627 GW=$(route -n | grep ^0.0.0.0 | awk '{print $2}')
632 echo "Can not find a getaway." >&2
637 ######################################################################
638 # Show the most recent files, no scroll
641 TERM_SIZE=($(stty size))
642 INVIS="${VT_GREEN_FG}${VT_RESET}"
643 \ls -goth --time-style="+${VT_GREEN_FG}%Y %b %d %H:%M${VT_RESET}" "$@" | \
644 head -$((TERM_SIZE[0]-2)) | cut -b1-$((TERM_SIZE[1]+${#INVIS}))
647 ######################################################################
651 # /screen selects low-resolution output
652 # /ebook selects medium-resolution output
653 # /printer selects "Print Optimized" setting.
654 # /prepress selects "Prepress Optimized" setting.
660 if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]
662 echo "$0 [<file.pdf>|--quality <screen|ebook|printer|prepress>] ..."
665 elif [[ "$1" == "--quality" ]]
672 result="$(basename "$1" .pdf)-${quality}.pdf"
673 echo -n "Generating ${result} with quality ${quality} ... "
674 gs -sDEVICE=pdfwrite \
675 -dCompatibilityLevel=1.4 \
676 -dPDFSETTINGS=/${quality} \
677 -dColorConversionStrategy=/LeaveColorUnchanged \
678 -dNOPAUSE -dQUIET -dBATCH \
679 -sOutputFile="${result}" "$1"
681 ls -hl "$1" "${result}"
684 echo "Cannot fine $1"
691 ######################################################################
692 # You can change the xterm background color on the fly!
694 function setxtermbg () {
695 echo -n $'\e]11;'$1$'\007'
698 ######################################################################
699 # Shuffle the lines from the stdin
701 function shuffle () {
703 [[ $SEED ]] || SEED=0
704 awk 'BEGIN{srand('${SEED}')} { print rand()" "$0 }' | sort -g | sed -e "s/^[0-9\.e\-]* //"
707 ######################################################################
708 # Stores the last entered command into a file
710 KEPT_COMMANDS=${HOME}/.kept_bash_commands
713 if [[ ${KEPT_COMMANDS} ]]
715 TOKEEP=$(mktemp /tmp/keep.XXXXXX)
718 echo "$@" > ${TOKEEP}
720 selector -b -i -d -l ${HISTSIZE} -o "${TOKEEP}" <(history)
723 if [[ -s "${TOKEEP}" ]]
725 echo $(date)": "$(cat ${TOKEEP}) >> ${KEPT_COMMANDS}
728 echo "No command stored!"
733 echo "You have to set \$KEPT_COMMANDS"
737 ######################################################################
738 # I sometime burn CDs and DVDs
741 [[ "${DEV_BURNER}" ]] || DEV_BURNER="/dev/sr0"
744 echo "burn <iso name | dirname>" >&2
747 if [[ $(file "$1" | \grep -E 'ISO 9660|UDF filesystem data') ]]
749 wodim -eject -v dev=${DEV_BURNER} "$1"
751 echo "Do not know what to do with $1" >&2
755 [[ "${TMP_ROOT}" ]] || TMP_ROOT=/tmp/
756 echo "Using ${TMP_ROOT} as temporary directory."
757 TMP=$(mktemp ${TMP_ROOT}/cdimage.XXXXXX) && \
758 genisoimage -input-charset iso8859-1 -r -o ${TMP} "$1" && \
759 wodim -eject -v dev=${DEV_BURNER} ${TMP}
762 echo "Can not find $1" >&2
766 ######################################################################
767 # And watch DVDs too!
772 echo " ! @ Seek to the beginning of the previous/next chapter"
773 echo " j Cycle through the available subtitles"
774 echo " o Show/hide the timing"
775 echo " x z Subtitle delay"
784 dvd_device="/dev/dvd"
795 # -vc ffmpeg12 -vf yadif
797 mplayer > /dev/null \
800 -alang en -slang en \
801 -softvol -softvol-max 1000 \
802 -dvd-device ${dvd_device} ${MPLAYER_OPTIONS} dvd://${title}
806 if [[ -e "/dev/dvd" ]]
808 DVD_DEVICE="/dev/dvd"
809 elif [[ -e "/dev/dvd3" ]]
811 DVD_DEVICE="/dev/dvd3"
813 echo "Can not find the dvd device." >&2
817 echo "Attemptin to rip from ${DVD_DEVICE}."
819 mkdir -p ${HOME}/dvds
822 time dvdbackup -i ${DVD_DEVICE} -v -M "$@" && eject
827 ######################################################################
828 # Create small images from images
830 function mksmall () {
832 if [[ "$1" == "--params" ]]
839 [[ "${PARAMS}" ]] || PARAMS="-geometry 1280x1024"
841 # Auto-orient does not seem to work at all, hence the ugly hack
844 # PARAMS="-auto-orient -geometry 800x600"
846 echo "Using ${PARAMS}"
850 [[ ${DEST_DIR} ]] || DEST_DIR=./small
854 if [[ ! -d ${DEST_DIR} ]]
856 echo "Can not create ${DEST_DIR}" >&2
860 NB_TOTAL=$(find -maxdepth 1 -type f | wc -l)
863 for i in $(find -maxdepth 1 -type f)
865 if [[ $(file $i | grep image) ]]
867 if [[ -e ${DEST_DIR}/$i ]]
869 echo "The file ${DEST_DIR}/$i already exists."
871 if [[ $(file ${i/%.*/}.* | grep -E movie) ]]
873 CAPTION_PARAMS="-font FreeSans-Bold -pointsize 32 -fill green -annotate +10+32 Video"
878 convert ${rotation_cmd} $i ${PARAMS} ${CAPTION_PARAMS} ${DEST_DIR}/$i
881 \ls -lt ${DEST_DIR}/$i
886 echo "$((NB*100/NB_TOTAL))% (${NB}/${NB_TOTAL})"
890 ######################################################################
891 # Move a file to the ~/sources/config directory and replace it where
892 # it was by a symbolic link
894 function mvtoconfig () {
895 CONFIGDIR=${HOME}/sources/config
896 if [[ -d ${CONFIGDIR} ]]
898 NEWNAME=${CONFIGDIR}/$(basename "$1" | sed -e "s/^\.//")
902 echo "Can not find ${CONFIGDIR}"
906 ######################################################################
907 # The complex prompt policy
911 if [[ "${CONSOLE}" == "yes" ]]
918 # If the login is a standard one (as specified in
919 # IGNORED_PROMPT_LOGIN, which is set in the private bash file), do not
920 # show it. I have IGNORED_PROMPT_LOGIN="^fleuret$".
922 if [[ ! ${IGNORED_PROMPT_LOGIN} ]] || [[ ! ${USER} =~ ${IGNORED_PROMPT_LOGIN} ]]
927 # If the display is not the main one, make the assumption that the
928 # shell is not running on the localhost, and show the hostname
930 [[ "${DISPLAY}" != ":0.0" ]] && IDENT="${IDENT}@\h"
932 # If there is the login or the hostname, add a ":" to the prompt
934 [[ "${IDENT}" ]] && IDENT="${IDENT}:"
936 if [[ ${USER} == "root" ]]
938 # If we are root, show that in red
939 PS1="\[${VT_RED_BG}${VT_WHITE_FG}\]${IDENT}\w\[${VT_RESET}\] "
941 if [[ $(\grep QEMU /proc/cpuinfo) ]]
943 # If we are in a qemu virtual machine, in yellow
944 PS1="\[${VT_YELLOW_BG}${VT_BLACK_FG}\]${IDENT}\w\[${VT_RESET}\] "
947 PS1="\[${VT_WHITE_BG}${VT_BLACK_FG}\]${IDENT}\w\[${VT_RESET}\] "
955 ######################################################################
956 # This implements a local history. If we are in a directory containing
957 # a writable local history file, we add the last line of the global
960 LOCAL_HISTORY_FILE=".local_bash_history"
962 function keep_local_history () {
963 if [[ -w "${LOCAL_HISTORY_FILE}" ]]
965 history 1 | sed -e 's/^ *[0-9]* *//' >> ${LOCAL_HISTORY_FILE}
966 TMP=$(mktemp /tmp/lh.XXXXXX)
968 uniq < ${LOCAL_HISTORY_FILE} | tail -${HISTSIZE} > ${TMP}
969 # mv would replace a symbolic link, while cp keeps it
970 \cp ${TMP} ${LOCAL_HISTORY_FILE}
972 LOCAL_HISTORY_HINT="* "
974 LOCAL_HISTORY_HINT=""
978 PS1="\[${VT_WHITE_BG}\]\${LOCAL_HISTORY_HINT}\[${VT_RESET}\]${PS1}"
980 ######################################################################
981 # Show the history path if it is unusual
983 function histfile_cue () {
984 if [[ ! "${HISTFILE}" == "${HOME}/.bash_history" ]]
986 HISTORY_CUE="[${HISTFILE}]"
992 PS1="\[${VT_YELLOW_BG}\]\${HISTORY_CUE}\[${VT_RESET}\]${PS1}"
994 ######################################################################
995 # The dus command is available on my web site
997 # git clone http://fleuret.org/git/dus/
999 alias dus='dus -f -i'
1001 ######################################################################
1002 # The finddup command is available on my web site
1004 # git clone http://fleuret.org/git/finddup/
1006 alias finddup='finddup -p'
1008 ######################################################################
1009 # The selector command is available on my web site
1011 # git clone http://fleuret.org/git/selector/
1013 export SELECTOR_CD_HISTORY_SIZE=10000
1015 source bash-selector.sh --hist --cd
1017 ######################################################################
1018 # And we avoid to put in the history the use of the selector, which we
1021 HISTIGNORE="${HISTIGNORE}:selector-history"
1023 ######################################################################
1025 function selector-printer () {
1026 TMP=$(mktemp /tmp/selector-printer.XXXXXX)
1027 selector -o ${TMP} <(lpstat -a | awk '{print $1}')
1028 export PRINTER=$(cat ${TMP})
1029 echo "PRINTER=${PRINTER}"
1034 ######################################################################
1035 # A ls with memory to notice what files have been added/removed from
1036 # the current directory
1039 [[ "${LSN_STATE_FILE}" ]] || LSN_STATE_FILE=".lsn-state"
1041 if [[ $1 == "--mem" ]] || [[ "$1" == "-m" ]]
1044 \ls -pa | sort > "${LSN_STATE_FILE}"
1045 echo "State updated." >&2
1047 elif [[ $1 == "+" ]]
1052 TMP=$(mktemp /tmp/lsn.XXXXXX)
1053 \ls -d "$@" > ${TMP}
1054 cat "${LSN_STATE_FILE}" >> ${TMP}
1055 sort ${TMP} | uniq -u > "${LSN_STATE_FILE}"
1061 lsn [--help|-h] [--mem|-m] [+ <file> ...]
1069 stores the current state of the directory
1071 + <file> [<file> ...]
1072 switches the presence/absence of the indicated files in the
1076 if [[ ! "$1" == "-h" ]] && [[ ! "$1" == "--help" ]]
1078 echo >&2 "Unknown option \`\`$1''."
1084 if [[ -f "${LSN_STATE_FILE}" ]]
1086 TMP=$(mktemp /tmp/lsn.XXXXXX)
1087 \ls -pa | sort > ${TMP}
1088 if diff > /dev/null ${TMP} "${LSN_STATE_FILE}"
1090 echo "${VT_GREEN_FG}${VT_BOLD}No change (since $(date +"%b %d, %Y" -r "${LSN_STATE_FILE}"))${VT_RESET}"
1092 \comm -1 -3 "${LSN_STATE_FILE}" ${TMP}
1093 \comm -2 -3 "${LSN_STATE_FILE}" ${TMP} | while read line
1095 echo "${VT_RED_FG}${VT_BOLD}${line}${VT_RESET} (missing)"
1100 echo "${VT_RED_FG}${VT_BOLD}No lsn state here.${VT_RESET}" >&2
1107 ######################################################################
1109 function prompt_command () {
1110 [[ "${CORE_CHECK_PWD}" == ${PWD} ]] || find . -maxdepth 1 -name "core__*" | awk '{print "'${VT_RED_FG}'"$0"'${VT_RESET}'"}'
1111 CORE_CHECK_PWD=${PWD}
1113 # if [[ $(umask) != 0022 ]]
1115 # echo "Umask changed to $(umask)"
1117 # save the history after every command to avoid loosing some when
1118 # multiple shells are open
1120 # load the saved history
1122 # and the local histories system defined above
1124 # and the history cue
1128 PROMPT_COMMAND="prompt_command"
1130 ######################################################################
1132 # Displaying the timezone if it is set
1134 [[ ${TZ} ]] && echo "${VT_BLUE_FG}Time zone is ${TZ}.${VT_RESET}"
1136 ######################################################################
1138 source /usr/share/bash-completion/bash_completion