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/'
143 # function catscan () {
144 # 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
147 function trash-later () {
148 dir=${HOME}/misc/trash-later/remove-after-$(date --date='+3 months' +%Y-%b-%d)
154 export HISTFILE=/dev/null
158 function select-tz () {
159 # Select a value for TZ
160 TMP=$(mktemp /tmp/select-tz.XXXXXX)
161 selector -o "${TMP}" <(grep -v ^# /usr/share/zoneinfo/zone.tab | awk '{print $3}' | sort -u)
167 if [[ $1 ]] && which winshepherd.sh
169 play -q ~/local/sounds/deskbell.wav &
171 winshepherd.sh message green "$1"
173 play -q ~/local/sounds/deskbell.wav
177 alias impressive="impressive -s -D 1000 -t Crossfade -T 100"
179 if [[ -e "${HOME}/.dircolors" ]]
181 eval $(dircolors "${HOME}/.dircolors")
182 alias ls='ls -p --group-directories-first --color'
183 alias lt='ls -p --color -gohtr --time-style="+%Y %b %d %H:%M"'
184 alias ll='ls -p --color -goh --time-style="+%Y %b %d %H:%M"'
185 alias lll='ls -p --color -lth'
186 alias l='ls -p --color -I "*~" -I "*.o"'
189 alias ls='ls -p --group-directories-first'
190 alias lt='ls -p -gohtr --time-style="+%Y %b %d %H:%M"'
191 alias ll='ls -p -goh --time-style="+%Y %b %d %H:%M"'
192 alias lll='ls -p -lth'
193 alias l='ls -p -I "*~" -I "*.o"'
196 ######################################################################
197 # Ignored extensions when completing
199 # export FIGNORE="CVS"
201 function latexdiff () {
203 -w $'\033[30;41m' -x $'\033[0m' \
204 -y $'\033[30;42m' -z $'\033[0m' \
208 # Looks for the most recent .log and pdflatex + bibtex the
209 # corresponding tex file
212 # RECENT_LOG=$(ls -t $(find -maxdepth 1 -name "*.log" -type f) | head -1)
214 RECENT_LOG=$(ls -t *.log | head -1)
216 if [[ ${RECENT_LOG} ]]
218 FILEBASE="${RECENT_LOG/.log/}"
220 if [[ -f "${FILEBASE}.tex" ]]
223 pdflatex --shell-escape "${FILEBASE}"
225 pdflatex --shell-escape "${FILEBASE}"
226 pdflatex --shell-escape "${FILEBASE}"
230 if [[ "$1" == "-v" ]] || [[ "$1" == "--view" ]]
232 # xpdf "${FILEBASE}.pdf"
233 zathura "${FILEBASE}.pdf"
234 elif [[ "$1" == "-p" ]] || [[ "$1" == "--print" ]]
236 lpr "${FILEBASE}.pdf"
238 echo "Usage: rl [-v|--view] [-p|--print]" >&2
239 echo "Unknown option $1" >&2
246 echo "Can not find a tex file corresponding to the most recent log (${RECENT_LOG/.log/})." >&2
252 echo "Can not find a recent log." >&2
258 ######################################################################
261 # http://www.reddit.com/r/linux/comments/2cgu5k/a_handy_little_script_for_interacting_with_your/
263 if [[ -t 0 ]] && [[ -z "$1" ]]
265 # output contents of clipboard
266 xclip -out -selection clipboard || exit 1
269 # copy file contents to clipboard
270 xclip -in -selection clipboard < "$1" || exit 1
272 # copy stdin to clipboard
273 xclip -in -selection clipboard <&0 || exit 1
277 # Find a file whose name contains a substring
282 find "$@" -name "*${name}*";
296 while [[ -f "${HOME}/scan-${n}.jpg" ]]
303 if [[ "$1" == "color" ]]
305 OPTS+=" --mode Color"
306 elif [[ "$1" == "gray" ]]
309 elif [[ "$1" == "a4crop" ]]
311 OPTS+=" -l 5 -t 0 -x 200 -y 300"
312 elif [[ "$1" == "help" ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]
314 echo "$0 [color|gray] [a4crop]" && return 0
316 echo "Unknown argument \`$1'"
322 echo "** Scanning to ${HOME}/scan-${n}.jpg"
325 SCANNER=$(scanimage -L | grep "Canon LiDE 60" | sed -e "s/^.*\`\(.*\)'.*$/\1/")
327 scanimage -d ${SCANNER} \
334 convert -rotate 180 - "${HOME}/scan-${n}.jpg"
339 # A password generator
342 if [[ "$1" == "-e" ]]
344 PW=$(tr -dc A-Z0-9 < /dev/urandom | head -c6)
347 PW=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c16)
349 if [[ ! "$1" == "-s" ]]
351 echo "$(date) ${PW}" >> ${HOME}/private/genpw.log
354 # tr -dc [:graph:] < /dev/urandom | head -c16
360 [[ "$1" ]] || ( echo "Universal unarchive: ua <file> [<file> ...]" >&2 && return 1)
366 *.tgz|*.tar.gz|*.tbz|*.tar.bz2)
379 echo "Unknown file extension $1"
388 # Create a dir and cd there
395 # Capture the screen in a dated png
402 name="capture-$(date +%Y%m%d-%H%M%S).png"
407 echo "Waiting $1 s and saving to ${name}."
410 echo "Saving to ${name}."
413 echo "Please click on the window to capture."
414 xwd | convert xwd:- ${name}
418 # Create and CD in a /tmp/tmp.XXXXXX directory. With the '-'
419 # arguments, do not create one and CD in the most recent instead
426 cd $(\ls -td /tmp/tmp.?????? | head -1)
428 echo "USAGE: cdt [-]" >&2
432 dir=$(mktemp -d /tmp/tmp.XXXXXX)
438 if [[ ! -a ${link} ]]
451 [[ "${TRASH_LATER_ROOT}" ]] || TRASH_LATER_ROOT="${HOME}/.trash"
453 if [[ "$1" == "--" ]]
456 elif [[ "$1" == "-l" ]]
459 echo "Trashin in 3 months"
460 TRASH_DIR="${TRASH_LATER_ROOT}/remove-after-$(date --date='+3 months' +%Y-%b-%d)"
461 mkdir -p "${TRASH_DIR}"
463 TRASH_DIR=$(date +/tmp/trash-${USER}-%Y-%b-%d-%Hh)
465 mkdir -p ${TRASH_DIR}
466 [[ -h ${LINK} ]] && \rm ${LINK}
467 [[ ! -f ${LINK} ]] && ln -s ${TRASH_DIR} ${LINK}
470 mv "$@" "${TRASH_DIR}"
474 function trashlatex () {
475 TRASH=$(date +/tmp/trash-latex-${USER}-%Y-%b-%d-%Hh)
480 [[ -h ${LINK} ]] && \rm ${LINK}
482 [[ ! -f ${LINK} ]] && ln -s ${TRASH} ${LINK}
485 *.log *.pdf *.aux *.nav *.pdfpc *.snm *.toc *.out \
487 *.*.table *.*.gnuplot \
491 ######################################################################
492 ## A version of pho which stores the image numbers in environment
496 TEMP=$(mktemp /tmp/pho.XXXXXXX)
497 $(which pho) "$@" | tee ${TEMP}
498 PHO_NOTE_1=$(grep ^"Note 1: " ${TEMP} | sed -e "s/^[^:]*: //")
499 PHO_NOTE_2=$(grep ^"Note 2: " ${TEMP} | sed -e "s/^[^:]*: //")
500 PHO_NOTE_3=$(grep ^"Note 3: " ${TEMP} | sed -e "s/^[^:]*: //")
501 PHO_NOTE_R90=$(grep ^"Rotate 90 \(CW\): " ${TEMP} | sed -e "s/^[^:]*: //")
502 PHO_NOTE_R180=$(grep ^"Rotate 180: " ${TEMP} | sed -e "s/^[^:]*: //")
503 PHO_NOTE_R270=$(grep ^"Rotate -90 \(CCW\): " ${TEMP} | sed -e "s/^[^:]*: //")
504 [[ "${PHO_NOTE_1}" ]] || unset PHO_NOTE_1
505 [[ "${PHO_NOTE_2}" ]] || unset PHO_NOTE_2
506 [[ "${PHO_NOTE_3}" ]] || unset PHO_NOTE_3
507 [[ "${PHO_NOTE_R90}" ]] || unset PHO_NOTE_R90
508 [[ "${PHO_NOTE_R180}" ]] || unset PHO_NOTE_R180
509 [[ "${PHO_NOTE_R270}" ]] || unset PHO_NOTE_R270
513 ######################################################################
514 ## A version of date that shows the time at home if TZ is set
517 echo "Local - $(date)"
519 echo "Home - $(date)"
522 ######################################################################
523 ## ifup / ifdown with sudo
525 [ ${NETUP_HISTORY} ] || NETUP_HISTORY="${HOME}/.netup_history"
530 [[ "${WIFI_INTERFACE}" ]] || WIFI_INTERFACE=wlan0
532 if [[ "$1" == "--scan" ]]
534 if ifconfig -s | grep -v -q ${WIFI_INTERFACE}
536 sudo ifconfig ${WIFI_INTERFACE} up
540 sudo iwlist ${WIFI_INTERFACE} scan | \grep -E 'ESS|Quali|Encry' | sed -e 's/^[ \t]*//'
542 if [[ ${upped_wifi} ]]
544 sudo ifconfig ${WIFI_INTERFACE} down
551 if \ifconfig -s | grep -q -v ^'(Iface|lo|docker[0-9]) '
553 echo "There is/are already interface(s) up." >&2
557 if \ps h -C dhclient | grep -q .
559 echo "There is already a dhcp client running." >&2
563 if \ps h -C wpa_supplicant | grep -q .
565 echo "There is already a wpa_supplicant running." >&2
569 if [[ ! "$@" ]] && [[ -s ${NETUP_HISTORY} ]]
571 echo "netup <interface>" >&2
573 # # If we have no argument and there is a .netup_history, use it
574 # ARGS=$(cat ${NETUP_HISTORY})
576 # Otherwise uses the given arguments, and store them
578 echo ${ARGS} > ${NETUP_HISTORY}
581 if [[ "${PRIVATE_INTERFACE_DEFINITION}" ]]
583 ARGS="-i ${PRIVATE_INTERFACE_DEFINITION} ${ARGS}"
586 echo "Executing ${VT_GREEN_FG}[sudo ifup ${ARGS}]${VT_RESET}"
589 # Ugly hack to remove the dsl modem dns server when we add
590 # explicitely a dns in the /etc/network/interfaces
592 REMOVE_LOCAL_DNS=/usr/local/bin/remove-local-dns.sh
593 # REMOVE_LOCAL_DNS=${HOME}/sources/scripts/remove-local-dns.sh
595 if [[ -x ${REMOVE_LOCAL_DNS} ]]
597 echo "Executing ${VT_GREEN_FG}[sudo ${REMOVE_LOCAL_DNS} 192.168]${VT_RESET}"
598 sudo ${REMOVE_LOCAL_DNS} 192.168
602 function netdown () {
603 if [[ ! "$@" ]] && [[ -s ${NETUP_HISTORY} ]]
605 # If there are no arguments and there is a .netup_history, get the
607 ARGS=$(tail -1 ${NETUP_HISTORY} | sed -e "s/=.*$//")
609 # Otherwise, use the standard ifdown
613 [[ "${PRIVATE_INTERFACE_DEFINITION}" ]] && ARGS="-i ${PRIVATE_INTERFACE_DEFINITION} ${ARGS}"
615 echo "Executing sudo ${VT_GREEN_FG}[ifdown ${ARGS}]${VT_RESET}"
618 # if [[ $(\ps -C dhclient | tail -n +2) ]]
620 # echo "There is still a dhcp client running." >&2
624 # if [[ $(\ps -C wpa_supplicant | tail -n +2) ]]
626 # echo "There is still a wpa_supplicant running." >&2
631 function checkgw () {
632 GW=$(route -n | grep ^0.0.0.0 | awk '{print $2}')
637 echo "Can not find a getaway." >&2
642 ######################################################################
643 # Show the most recent files, no scroll
646 TERM_SIZE=($(stty size))
647 INVIS="${VT_GREEN_FG}${VT_RESET}"
648 \ls -goth --time-style="+${VT_GREEN_FG}%Y %b %d %H:%M${VT_RESET}" "$@" | \
649 head -$((TERM_SIZE[0]-2)) | cut -b1-$((TERM_SIZE[1]+${#INVIS}))
652 ######################################################################
656 # /screen selects low-resolution output
657 # /ebook selects medium-resolution output
658 # /printer selects "Print Optimized" setting.
659 # /prepress selects "Prepress Optimized" setting.
665 if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]
667 echo "$0 [<file.pdf>|--quality <screen|ebook|printer|prepress>] ..."
670 elif [[ "$1" == "--quality" ]]
677 result="$(basename "$1" .pdf)-${quality}.pdf"
678 echo -n "Generating ${result} with quality ${quality} ... "
679 gs -sDEVICE=pdfwrite \
680 -dCompatibilityLevel=1.4 \
681 -dPDFSETTINGS=/${quality} \
682 -dColorConversionStrategy=/LeaveColorUnchanged \
683 -dNOPAUSE -dQUIET -dBATCH \
684 -sOutputFile="${result}" "$1"
686 ls -hl "$1" "${result}"
689 echo "Cannot fine $1"
696 ######################################################################
697 # You can change the xterm background color on the fly!
699 function setxtermbg () {
700 echo -n $'\e]11;'$1$'\007'
703 ######################################################################
704 # Shuffle the lines from the stdin
706 function shuffle () {
708 [[ $SEED ]] || SEED=0
709 awk 'BEGIN{srand('${SEED}')} { print rand()" "$0 }' | sort -g | sed -e "s/^[0-9\.e\-]* //"
712 ######################################################################
713 # Stores the last entered command into a file
715 KEPT_COMMANDS=${HOME}/.kept_bash_commands
718 if [[ ${KEPT_COMMANDS} ]]
720 TOKEEP=$(mktemp /tmp/keep.XXXXXX)
723 echo "$@" > ${TOKEEP}
725 selector -b -i -d -l ${HISTSIZE} -o "${TOKEEP}" <(history)
728 if [[ -s "${TOKEEP}" ]]
730 echo $(date)": "$(cat ${TOKEEP}) >> ${KEPT_COMMANDS}
733 echo "No command stored!"
738 echo "You have to set \$KEPT_COMMANDS"
742 ######################################################################
743 # I sometime burn CDs and DVDs
746 [[ "${DEV_BURNER}" ]] || DEV_BURNER="/dev/sr0"
749 echo "burn <iso name | dirname>" >&2
752 if [[ $(file "$1" | \grep -E 'ISO 9660|UDF filesystem data') ]]
754 wodim -eject -v dev=${DEV_BURNER} "$1"
756 echo "Do not know what to do with $1" >&2
760 [[ "${TMP_ROOT}" ]] || TMP_ROOT=/tmp/
761 echo "Using ${TMP_ROOT} as temporary directory."
762 TMP=$(mktemp ${TMP_ROOT}/cdimage.XXXXXX) && \
763 genisoimage -input-charset iso8859-1 -r -o ${TMP} "$1" && \
764 wodim -eject -v dev=${DEV_BURNER} ${TMP}
767 echo "Can not find $1" >&2
771 ######################################################################
772 # And watch DVDs too!
777 echo " ! @ Seek to the beginning of the previous/next chapter"
778 echo " j Cycle through the available subtitles"
779 echo " o Show/hide the timing"
780 echo " x z Subtitle delay"
789 dvd_device="/dev/dvd"
800 # -vc ffmpeg12 -vf yadif
802 mplayer > /dev/null \
805 -alang en -slang en \
806 -softvol -softvol-max 1000 \
807 -dvd-device ${dvd_device} ${MPLAYER_OPTIONS} dvd://${title}
811 if [[ -e "/dev/dvd" ]]
813 DVD_DEVICE="/dev/dvd"
814 elif [[ -e "/dev/dvd3" ]]
816 DVD_DEVICE="/dev/dvd3"
818 echo "Can not find the dvd device." >&2
822 echo "Attemptin to rip from ${DVD_DEVICE}."
824 mkdir -p ${HOME}/dvds
827 time dvdbackup -i ${DVD_DEVICE} -v -M "$@" && eject
832 ######################################################################
833 # Create small images from images
835 function mksmall () {
837 if [[ "$1" == "--params" ]]
844 [[ "${PARAMS}" ]] || PARAMS="-geometry 1280x1024"
846 # Auto-orient does not seem to work at all, hence the ugly hack
849 # PARAMS="-auto-orient -geometry 800x600"
851 echo "Using ${PARAMS}"
855 [[ ${DEST_DIR} ]] || DEST_DIR=./small
859 if [[ ! -d ${DEST_DIR} ]]
861 echo "Can not create ${DEST_DIR}" >&2
865 NB_TOTAL=$(find -maxdepth 1 -type f | wc -l)
868 for i in $(find -maxdepth 1 -type f)
870 if [[ $(file $i | grep image) ]]
872 if [[ -e ${DEST_DIR}/$i ]]
874 echo "The file ${DEST_DIR}/$i already exists."
876 if [[ $(file ${i/%.*/}.* | grep -E movie) ]]
878 CAPTION_PARAMS="-font FreeSans-Bold -pointsize 32 -fill green -annotate +10+32 Video"
883 convert ${rotation_cmd} $i ${PARAMS} ${CAPTION_PARAMS} ${DEST_DIR}/$i
886 \ls -lt ${DEST_DIR}/$i
891 echo "$((NB*100/NB_TOTAL))% (${NB}/${NB_TOTAL})"
895 ######################################################################
896 # Move a file to the ~/sources/config directory and replace it where
897 # it was by a symbolic link
899 function mvtoconfig () {
900 CONFIGDIR=${HOME}/sources/config
901 if [[ -d ${CONFIGDIR} ]]
903 NEWNAME=${CONFIGDIR}/$(basename "$1" | sed -e "s/^\.//")
907 echo "Can not find ${CONFIGDIR}"
912 ######################################################################
915 if which > /dev/null git
919 git 2>/dev/null rev-parse --abbrev-ref HEAD | sed -e 's/^\(.*\)$/(\1) /'
922 export PS_GIT="${VT_WHITE_BG}${VT_GREEN_FG}\$(parse_git_branch)${VT_RESET}"
925 ######################################################################
926 # The complex prompt policy
930 if [[ "${CONSOLE}" == "yes" ]]
937 # If the login is a standard one (as specified in
938 # IGNORED_PROMPT_LOGIN, which is set in the private bash file), do not
939 # show it. I have IGNORED_PROMPT_LOGIN="^fleuret$".
941 if [[ ! ${IGNORED_PROMPT_LOGIN} ]] || [[ ! ${USER} =~ ${IGNORED_PROMPT_LOGIN} ]]
946 # If the display is not the main one, make the assumption that the
947 # shell is not running on the localhost, and show the hostname
949 [[ "${DISPLAY}" != ":0.0" ]] && IDENT="${IDENT}@\h"
951 # If there is the login or the hostname, add a ":" to the prompt
953 [[ "${IDENT}" ]] && IDENT="${IDENT}:"
955 if [[ ${USER} == "root" ]]
957 # If we are root, show that in red
958 PS1="\[${VT_RED_BG}${VT_WHITE_FG}\]${IDENT}\w\[${VT_RESET}\] "
960 if [[ $(\grep QEMU /proc/cpuinfo) ]]
962 # If we are in a qemu virtual machine, in yellow
963 PS1="\[${VT_YELLOW_BG}${VT_BLACK_FG}\]${IDENT}\w\[${VT_RESET}\] "
966 PS1="\[${VT_WHITE_BG}${VT_BLACK_FG}\]${IDENT}\w\[${VT_RESET}\] "
972 PS1="${PS_GIT}${PSCUE}${PS1}"
974 ######################################################################
975 # This implements a local history. If we are in a directory containing
976 # a writable local history file, we add the last line of the global
979 LOCAL_HISTORY_FILE=".local_bash_history"
981 function keep_local_history () {
982 if [[ -w "${LOCAL_HISTORY_FILE}" ]]
984 history 1 | sed -e 's/^ *[0-9]* *//' >> ${LOCAL_HISTORY_FILE}
985 TMP=$(mktemp /tmp/lh.XXXXXX)
987 uniq < ${LOCAL_HISTORY_FILE} | tail -${HISTSIZE} > ${TMP}
988 # mv would replace a symbolic link, while cp keeps it
989 \cp ${TMP} ${LOCAL_HISTORY_FILE}
991 LOCAL_HISTORY_HINT="* "
993 LOCAL_HISTORY_HINT=""
997 PS1="\[${VT_WHITE_BG}\]\${LOCAL_HISTORY_HINT}\[${VT_RESET}\]${PS1}"
999 ######################################################################
1000 # Show the history path if it is unusual
1002 function histfile_cue () {
1003 if [[ ! "${HISTFILE}" == "${HOME}/.bash_history" ]]
1005 HISTORY_CUE="[${HISTFILE}]"
1011 PS1="\[${VT_YELLOW_BG}\]\${HISTORY_CUE}\[${VT_RESET}\]${PS1}"
1013 ######################################################################
1014 # The dus command is available on my web site
1016 # git clone http://fleuret.org/git/dus/
1018 alias dus='dus -f -i'
1020 ######################################################################
1021 # The finddup command is available on my web site
1023 # git clone http://fleuret.org/git/finddup/
1025 alias finddup='finddup -p'
1027 ######################################################################
1028 # The selector command is available on my web site
1030 # git clone http://fleuret.org/git/selector/
1032 export SELECTOR_CD_HISTORY_SIZE=10000
1034 source bash-selector.sh --hist --cd
1036 ######################################################################
1037 # And we avoid to put in the history the use of the selector, which we
1040 HISTIGNORE="${HISTIGNORE}:selector-history"
1042 ######################################################################
1044 function selector-printer () {
1045 TMP=$(mktemp /tmp/selector-printer.XXXXXX)
1046 selector -o ${TMP} <(lpstat -a | awk '{print $1}')
1047 export PRINTER=$(cat ${TMP})
1048 echo "PRINTER=${PRINTER}"
1053 ######################################################################
1054 # A ls with memory to notice what files have been added/removed from
1055 # the current directory
1058 [[ "${LSN_STATE_FILE}" ]] || LSN_STATE_FILE=".lsn-state"
1060 if [[ $1 == "--mem" ]] || [[ "$1" == "-m" ]]
1063 \ls -pa | sort > "${LSN_STATE_FILE}"
1064 echo "State updated." >&2
1066 elif [[ $1 == "+" ]]
1071 TMP=$(mktemp /tmp/lsn.XXXXXX)
1072 \ls -d "$@" > ${TMP}
1073 cat "${LSN_STATE_FILE}" >> ${TMP}
1074 sort ${TMP} | uniq -u > "${LSN_STATE_FILE}"
1080 lsn [--help|-h] [--mem|-m] [+ <file> ...]
1088 stores the current state of the directory
1090 + <file> [<file> ...]
1091 switches the presence/absence of the indicated files in the
1095 if [[ ! "$1" == "-h" ]] && [[ ! "$1" == "--help" ]]
1097 echo >&2 "Unknown option \`\`$1''."
1103 if [[ -f "${LSN_STATE_FILE}" ]]
1105 TMP=$(mktemp /tmp/lsn.XXXXXX)
1106 \ls -pa | sort > ${TMP}
1107 if diff > /dev/null ${TMP} "${LSN_STATE_FILE}"
1109 echo "${VT_GREEN_FG}${VT_BOLD}No change (since $(date +"%b %d, %Y" -r "${LSN_STATE_FILE}"))${VT_RESET}"
1111 \comm -1 -3 "${LSN_STATE_FILE}" ${TMP}
1112 \comm -2 -3 "${LSN_STATE_FILE}" ${TMP} | while read line
1114 echo "${VT_RED_FG}${VT_BOLD}${line}${VT_RESET} (missing)"
1119 echo "${VT_RED_FG}${VT_BOLD}No lsn state here.${VT_RESET}" >&2
1126 ######################################################################
1128 function prompt_command () {
1129 [[ "${CORE_CHECK_PWD}" == ${PWD} ]] || find . -maxdepth 1 -name "core__*" | awk '{print "'${VT_RED_FG}'"$0"'${VT_RESET}'"}'
1130 CORE_CHECK_PWD=${PWD}
1132 # if [[ $(umask) != 0022 ]]
1134 # echo "Umask changed to $(umask)"
1136 # save the history after every command to avoid loosing some when
1137 # multiple shells are open
1139 # load the saved history
1141 # and the local histories system defined above
1143 # and the history cue
1147 PROMPT_COMMAND="prompt_command"
1149 ######################################################################
1151 # Displaying the timezone if it is set
1153 [[ ${TZ} ]] && echo "${VT_BLUE_FG}Time zone is ${TZ}.${VT_RESET}"
1155 ######################################################################
1157 source /usr/share/bash-completion/bash_completion