diff options
author | LAN-TW <lantw44@gmail.com> | 2011-11-29 00:36:36 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2011-11-29 00:36:36 +0800 |
commit | d10c4bb2a07d8aca27c98ea4462ca3f4693bab85 (patch) | |
tree | 3bcf23eb86afbc42b5dcd9b33067a3ca44b98a26 /bash_include | |
parent | d11761e89ee58119649fba4ff4c44cd1a62e25ea (diff) | |
download | configfile-d10c4bb2a07d8aca27c98ea4462ca3f4693bab85.tar configfile-d10c4bb2a07d8aca27c98ea4462ca3f4693bab85.tar.gz configfile-d10c4bb2a07d8aca27c98ea4462ca3f4693bab85.tar.bz2 configfile-d10c4bb2a07d8aca27c98ea4462ca3f4693bab85.tar.lz configfile-d10c4bb2a07d8aca27c98ea4462ca3f4693bab85.tar.xz configfile-d10c4bb2a07d8aca27c98ea4462ca3f4693bab85.tar.zst configfile-d10c4bb2a07d8aca27c98ea4462ca3f4693bab85.zip |
bash_include: 加入歷史紀錄檔保護與備份功能bash_include-20111128
Diffstat (limited to 'bash_include')
-rw-r--r-- | bash_include | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/bash_include b/bash_include index 2a4d476..99936d0 100644 --- a/bash_include +++ b/bash_include @@ -1,15 +1,47 @@ +#!/bin/bash +# +# --- UTF-8 --- +# +# 檔案製作者:lantw44 +# 更新日期:2011/11/28 +# + +echo "Running .bash_include" + +# Internal Variables + +default_tty_setting=`stty -g` + colorprompting='\[\e[1;31m\]\!\[\e[m\] [\[\e[1;33m\]\u\[\e[m\]@\[\e[1;32m\]\h\[\e[m\] \[\e[1;36m\]\w\[\e[m\]]\$ ' nocolorprompting='\! [\u@\h \w]\$ ' +historycountfile="$HOME/.bash_history.count" +historybackupfile="$HOME/.bash_history.bak" bgrunfiledir="$HOME/tmp/bgrun" -HISTSIZE=100000 -HISTFILESIZE=100000 +HISTSIZE=1000000 +HISTFILESIZE=1000000 +HISTCONTROL=ignoredups:ignorespace + + + + +# Environmental Variables + +export EDITOR=vim +export FCEDIT=vim +export PAGER=less + + + + +# Aliases alias startcolor='PS1=$colorprompting' alias stopcolor='PS1=$nocolorprompting' alias ll='ls -l' +alias grep='grep --color=always' alias rm='rm -i' alias cp='cp -pi' alias mv='mv -i' @@ -22,13 +54,13 @@ alias big5='LANG=zh_TW.Big5;LC_ALL=zh_TW.Big5' alias zhtw='LANG=zh_TW.UTF-8;LC_ALL=zh_TW.UTF-8' alias utf8='LANG=zh_TW.UTF-8;LC_ALL=zh_TW.UTF-8' -default_tty_setting=`stty -g` alias savetty='default_tty_setting=`stty -g`' alias resetty='stty $default_tty_setting' -alias sg='sudo -g' -# Function + + +# Functions function compile_all () { @@ -103,6 +135,8 @@ function mkscreenacl () done } +########## Background ########## + function bgrun () { [ "$#" = "0" ] && return 1 @@ -138,6 +172,8 @@ function bgcount () find "$bgrunfiledir" -maxdepth 1 -mindepth 1 | cut -d - -f 2,3 | wc | awk '{print $2}' } +########## Background ########## + function check_dmesg () { [ "$#" = "0" ] && return 1 @@ -153,9 +189,36 @@ function check_dmesg () done } +function prehistory_backup () +{ + echo "Running prehistory_backup" + currentcount=`wc "$HISTFILE" | awk '{print $1}'` + [ '!' -f "$historycountfile" ] && touch "$historycountfile" + declare -i previoushistorycount + previoushistorycount=`cat "$historycountfile"` + if [ "$currentcount" -lt "$previoushistorycount" ] + then + printf "\e[1;31mWarning\e[m: Your $HISTFILE may be MODIFIED BY OTHER PROGRAMS!\n" + printf "Note: \e[1;33m$currentcount\e[m < $previoushistorycount\n" + echo "Your $historycountfile and $historybackupfile will not be overwritten until this problem is fixed." + echo " 1. Check your $HISTFILE." + echo " 2. Edit your $HISTFILE manually if some unexpected changes are found." + echo " (You may need $historybackupfile to do it) " + echo " 3. Remove the file $historycountfile." + echo " 4. Run the command \`prehistory_backup' again." + return 1 + fi + echo "$currentcount" > "$historycountfile" + cp -f "$HISTFILE" "$historybackupfile" +} + + + + # Starting doing something startcolor +prehistory_backup umask 0022 @@ -167,5 +230,12 @@ then fi shopt -s histappend +shopt -s checkwinsize +shopt -s checkjobs +shopt -s checkhash +shopt -s cmdhist +shopt -s mailwarn + +echo "Done" -# ~/check_dmesg.sh 5 & +# check_dmesg.sh 5 & |