diff options
author | LAN-TW <lantw44@gmail.com> | 2013-12-02 23:04:13 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-12-02 23:04:13 +0800 |
commit | b5db6858f5c3a4130d356d028c281e1ac5304542 (patch) | |
tree | 2df668f3eb0109c274970b929b3be7e9e6f36dce /bash_include | |
parent | 1aa7227cb3b20ebc3593066b1a5837c280202c8d (diff) | |
download | configfile-b5db6858f5c3a4130d356d028c281e1ac5304542.tar configfile-b5db6858f5c3a4130d356d028c281e1ac5304542.tar.gz configfile-b5db6858f5c3a4130d356d028c281e1ac5304542.tar.bz2 configfile-b5db6858f5c3a4130d356d028c281e1ac5304542.tar.lz configfile-b5db6858f5c3a4130d356d028c281e1ac5304542.tar.xz configfile-b5db6858f5c3a4130d356d028c281e1ac5304542.tar.zst configfile-b5db6858f5c3a4130d356d028c281e1ac5304542.zip |
bash_include: 用 GREP_OPTIONS 代替 grep alias、加入未被 alias 的安全 alias
Diffstat (limited to 'bash_include')
-rw-r--r-- | bash_include | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/bash_include b/bash_include index 50a7c9d..703a881 100644 --- a/bash_include +++ b/bash_include @@ -107,6 +107,7 @@ export FCEDIT=vim export VISUAL=vim export PAGER=less export GCC_COLORS=1 +export GREP_OPTIONS='--color=always' # Aliases @@ -115,13 +116,22 @@ alias startcolor='PS1=$colorprompting; PS2=$colorsecondprompting' alias stopcolor='PS1=$nocolorprompting; PS2=$nocolorsecondprompting' alias ll='ls -l' -alias grep='grep --color=always' +alias la='ls -la' alias rm='rm -i' alias cp='cp -pi' alias mv='mv -i' alias jobs='jobs -l' alias less='less -RS' +# Non-aliased common tools (safe for use in script) +alias safe_ls='\ls' +alias safe_cp='\cp' +alias safe_mv='\mv' +alias safe_rm='\rm' +alias safe_jobs='\jobs' +alias safe_less='\less' +alias safe_grep='GREP_OPTIONS= \grep' + alias cccc='LANG=C;LANGUAGE=C;LC_ALL=C' alias enus='LANG=en_US.UTF-8;LANGUAGE=en_US:en;LC_ALL=en_US.UTF-8' alias big5='LANG=zh_TW.Big5;LANGUAGE=zh_TW:zh:en;LC_ALL=zh_TW.Big5' @@ -481,7 +491,7 @@ function prehistory_backup () echo "+$[$currentcount-$previoushistorycount])" fi echo "$currentcount" > "$historycountfile" - command cp -f "$HISTFILE" "$historybackupfile" + safe_cp -f "$HISTFILE" "$historybackupfile" } ########## Trash Manager ########## @@ -594,7 +604,7 @@ function trash_recover () if [ "$?" = "0" ] then echo "Remove: $oneline" - command rm -rf "$oneline" + rm -rf "$oneline" fi done } @@ -1094,7 +1104,7 @@ function fetch_and_merge () if fetch_remote_file "${local_file}.new" "${remote_file}" then if [ '!' -e "${local_file}" ]; then - mv -vf "${local_file}.new" "${local_file}" + safe_mv -vf "${local_file}.new" "${local_file}" else while true do @@ -1115,7 +1125,7 @@ function fetch_and_merge () read -e -p "[I]nstall/(K)eep/(R)etry/(D)iff/(M)erge ? " merge_cmd case "${merge_cmd}" in ''|I|i) - mv -vf "${local_file}.new" "${local_file}" + safe_mv -vf "${local_file}.new" "${local_file}" break ;; K|k) @@ -1239,8 +1249,8 @@ function backup_file () fi else history -s "$FUNCNAME" "$@" - "${prefixlist[@]}" cp -p "${arglist[$i]}" "$rootfilename" - history -s "${prefixlist[@]}" cp -p "${arglist[$i]}" "$rootfilename" + "${prefixlist[@]}" \cp -p "${arglist[$i]}" "$rootfilename" + history -s "${prefixlist[@]}" \cp -p "${arglist[$i]}" "$rootfilename" "${prefixlist[@]}" touch -r "${arglist[$i]}" "$rootfilename" history -s "${prefixlist[@]}" touch -r "${arglist[$i]}" "$rootfilename" fi @@ -1269,8 +1279,8 @@ function get_memory_info () { case "$OSTYPE" in *linux*|*gnu*) - local meminfoline="`free -m | command grep -i mem`" - local swapinfoline="`free -m | command grep -i swap`" + local meminfoline="`free -m | safe_grep -i mem`" + local swapinfoline="`free -m | safe_grep -i swap`" local memtotal="`echo "$meminfoline" | awk '{print $2}'`" local memused="`echo "$meminfoline" | awk '{print $3}'`" local membuf="`echo "$meminfoline" | awk '{print $6}'`" @@ -1620,7 +1630,7 @@ function freebsd_ports_should_rebuild () { /usr/local/bin/* /usr/local/sbin/* \ /usr/local/lib/* /usr/local/libexec/* \ /usr/local/libexec/*/* \ - 2>/dev/null | grep 'not found' | \ + 2>/dev/null | grep_safe 'not found' | \ { while read oneline; do echo ${oneline} | cut -d ' ' -f 1; done; } | uniq) reqpkg=$({ for i in $reqcomp; do pkg_info -q -W $i; done } | sort | uniq) echo $reqpkg |