diff options
author | LAN-TW <lantw44@gmail.com> | 2013-07-04 22:23:22 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-07-04 22:23:22 +0800 |
commit | ce1f3be48858c53066722b180ce535cfafc4484e (patch) | |
tree | 0635812629f13b1afbdf48b9e10c6895f17e9430 | |
parent | 004bbf6579c0f6df6b59916d4a76c0323fa11fbe (diff) | |
download | configfile-ce1f3be48858c53066722b180ce535cfafc4484e.tar configfile-ce1f3be48858c53066722b180ce535cfafc4484e.tar.gz configfile-ce1f3be48858c53066722b180ce535cfafc4484e.tar.bz2 configfile-ce1f3be48858c53066722b180ce535cfafc4484e.tar.lz configfile-ce1f3be48858c53066722b180ce535cfafc4484e.tar.xz configfile-ce1f3be48858c53066722b180ce535cfafc4484e.tar.zst configfile-ce1f3be48858c53066722b180ce535cfafc4484e.zip |
bash_include: compile_all 可自訂編譯器、移除行尾空白 | vimrc: cscope 快速鍵vimrc-20130704bash_include-20130704
-rw-r--r-- | bash_include | 100 | ||||
-rw-r--r-- | vimrc | 14 |
2 files changed, 66 insertions, 48 deletions
diff --git a/bash_include b/bash_include index 5bb5daa..86777ea 100644 --- a/bash_include +++ b/bash_include @@ -21,7 +21,7 @@ colorprompting='\[\e[1;31m\]\!\[\e[m\] [\[\e[1;33m\]\u\[\e[m\]@\[\e[1;32m\]\h\[\ nocolorprompting='\! [\u@\h \w]' if [ "$SSH_CONNECTION" ] -then +then colorprompting="\[\e[1;44m\]*\[\e[m\]$colorprompting" nocolorprompting="*$nocolorprompting" fi @@ -105,6 +105,8 @@ alias vimhtml='vim -c "set ts=2" -c "set sw=2"' function compile_all () { local noask=0 + local mycc="${CC}" + local mycxx="${CPP}" [ "$1" = '' ] && echo "Which file(s) do you want to compile? " && return 1 [ "$1" = "-n" ] && noask=1 if [ "$noask" = "0" ]; then @@ -115,6 +117,8 @@ function compile_all () else shift fi + [ -z "${mycc}" ] && mycc=cc + [ -z "${mycxx}" ] && mycxx=c++ while [ "$1" '!=' '' ] do local TARGETFILE="`echo "$1" | cut -d . -f 1`" @@ -122,17 +126,17 @@ function compile_all () if [ -f "$1" ]; then true else - printf\ - "\e[1;33mWarning\e[0m: $1 Non-existent file or not a regular file\n" + printf\ + "\e[1;33mWarning\e[0m: $1 Non-existent file or not a regular file\n" shift ; continue fi [ "$TARGETFILE" = "$1" ] && shift && continue if [ "$SUFFIX" = "c" ]; then - echo "[CC] $1 -> $TARGETFILE" - gcc $CFLAGS "$1" $LDFLAGS -o "$TARGETFILE" + echo "[${mycc}] $1 -> $TARGETFILE" + ${mycc} $CFLAGS "$1" $LDFLAGS -o "$TARGETFILE" elif [ "$SUFFIX" = "cpp" ]; then - echo "[CXX] $1 -> $TARGETFILE" - g++ $CFLAGS "$1" $LDFLAGS -o "$TARGETFILE" + echo "[${mycxx}] $1 -> $TARGETFILE" + ${mycxx} $CFLAGS "$1" $LDFLAGS -o "$TARGETFILE" else printf "$1: Unknown suffix (\e[1;33mskipped\e[0m)\n" fi @@ -149,7 +153,7 @@ function convert_to_html () while [ "$1" '!=' '' ] do for i in "$1" - do + do vim $i -c 'set background=dark' \ -c 'highlight PreProc ctermfg=darkcyan' \ -c "$BEFORE_CONVERT_TO_HTML" \ @@ -157,7 +161,7 @@ function convert_to_html () -c "$BEFORE_CONVERT_TO_HTML2" \ -c TOhtml \ -c :w \ - -c :qa + -c :qa done shift done @@ -172,19 +176,19 @@ function mkscreenacl () do echo "aclchg $1 +x $i" done - echo "aclchg $1 -rw \"\#?\"" + echo "aclchg $1 -rw \"\#?\"" shift done } -function get_file_size () +function get_file_size () { split_arguments "$@" - "${prefixlist[@]}" du -s "${arglist[@]}" | { + "${prefixlist[@]}" du -s "${arglist[@]}" | { read -d " " dirsize echo "$dirsize" read throwaway - } + } unset arglist unset prefixlist } @@ -213,7 +217,7 @@ function bgrun () { echo -n "$BASHPID " > "$filename" echo "$@" >> "$filename" - exec "$@" &>> "$filename" + exec "$@" &>> "$filename" } & } @@ -261,7 +265,7 @@ function bglist () read -n 2 part_hour read -n 2 part_minute read -n 2 part_second - printf '%6d' "$i" + printf '%6d' "$i" echo " $part_year-$part_month-$part_date $part_hour:$part_minute:$part_second $cmdline" } i=$i+1 @@ -339,7 +343,7 @@ function bgclean () unset prefixlist } -function bgdu () +function bgdu () { local -i j=1 { @@ -374,7 +378,7 @@ function check_dmesg () sleep $1 [ "$?" '!=' "0" ] && return 1 FIRST_RUN=0 - done + done } function check_system_status () @@ -404,7 +408,7 @@ function check_system_status () fi sleep $1 first_run=0 - done + done } function prehistory_backup () @@ -420,7 +424,7 @@ function prehistory_backup () 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 " 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." @@ -458,7 +462,7 @@ function trash_mv () split_arguments "$@" while [ "${arglist[$i]}" ] do - original_path="`$REALPATH_PROGRAM "${arglist[$i]}"`" + original_path="`"${prefixlist[@]}" $REALPATH_PROGRAM "${arglist[$i]}"`" current_time=`date "+%Y%m%d-%H%M%S"` better_time=`date "+%Y-%m-%d %H:%M:%S"` dirname="`basename "${arglist[$i]}" | sed -e 's/-/_/g' -e 's/ /_/g'`" @@ -555,7 +559,7 @@ function trash_recover () unset prefixlist } -function trash_count () +function trash_count () { find "$trashdir" -mindepth 1 -maxdepth 1 | wc | awk '{print $2}' } @@ -629,7 +633,7 @@ function split_path_core () unset oneline } -function split_path () +function split_path () { coproc split_path_core readarray -t -u ${COPROC[0]} patharr @@ -645,7 +649,7 @@ function update_path () do if [ '!' "${patharr[$i]}" = "^" ] then - if [ "$firsttime" ] + if [ "$firsttime" ] then firsttime='' else @@ -705,7 +709,7 @@ function old_path_editor_core () ;; E|e) read -e -p "Index: " command_sub - read -e -p "Modify this entry: " -i "${patharr[$command_sub]}" patharr[$command_sub] + read -e -p "Modify this entry: " -i "${patharr[$command_sub]}" patharr[$command_sub] update_path ;; M|m) @@ -725,7 +729,7 @@ function old_path_editor_core () current_path="$PATH" fi ;; - Q|q) + Q|q) if [ "$1" = "ld" ] then export LD_LIBRARY_PATH="$current_path" @@ -857,7 +861,7 @@ function path_editor () ;; E|e) read -e -p "Index: " command_sub - read -e -p "Modify this entry: " -i "${newpath[$command_sub]}" newpath[$command_sub] + read -e -p "Modify this entry: " -i "${newpath[$command_sub]}" newpath[$command_sub] ;; M|m) read -e -p "From: " command_sub @@ -898,7 +902,7 @@ function path_editor () newpath_init fi ;; - Q|q) + Q|q) newpath_gen eval export ${newpathvarname}=\"$pathmodval\" echo "${newpathvarname}=$pathmodval" @@ -955,7 +959,7 @@ function editlink () i=$i+1 continue fi - if [ "$newdest" ] && [ "$newdest" '!=' "$orgdest" ]; then + if [ "$newdest" ] && [ "$newdest" '!=' "$orgdest" ]; then "${prefixlist[@]}" rm -f "${arglist[$i]}" "${prefixlist[@]}" ln -sv "$newdest" "${arglist[$i]}" fi @@ -974,8 +978,8 @@ function backup_file () local -i j while [ "${arglist[$i]}" ] do - if [ '!' -f "${arglist[$i]}" ] - then + if [ '!' -f "${arglist[$i]}" ] + then printf "\e[1;31mError\e[m: ${arglist[$i]} does not exist or it is not a regular file.\n" i=$i+1 continue @@ -1033,7 +1037,7 @@ function keep_sudo_credential () function get_memory_info () { case "`uname`" in - "Linux"|"GNU") + "Linux"|"GNU") local meminfoline="`free -m | \grep -i mem`" local swapinfoline="`free -m | \grep -i swap`" local memtotal="`echo "$meminfoline" | awk '{print $2}'`" @@ -1110,7 +1114,7 @@ function mvfile () [ "$1" = "-n" ] && nocheck=1 && shift split_arguments "$@" local -i i=0 - while [ "${arglist[$i]}" ] + while [ "${arglist[$i]}" ] do if [ "$nocheck" = "0" ] && [ '!' -e "${arglist[$i]}" ] then @@ -1137,31 +1141,31 @@ function createdir_askmode () newdir_mode="$2" if mkdir -p "$1" then - echo "Directory $1 is created." + echo "Directory $1 is created." printf "Change the mode of the directory... " read -i "$newdir_mode" -p ">>> Mode: " -e newdir_mode chmod "$newdir_mode" "$1" else echo "Cannot create directory $1!" return 1 - fi + fi } function get_terminal_size () { - # ESC 7 = 儲存游標位置和屬性 + # ESC 7 = 儲存游標位置和屬性 # ESC [r = 啟用全螢幕捲動 # ESC [{row};{col}H = 移動游標 # ESC 6n = 回報目前游標位置 # ESC 8 = 還原游標位置和屬性 - echo -n $'\e7\e[r\e[999;999H\e[6n\e8' 1>&2 + echo -n $'\e7\e[r\e[999;999H\e[6n\e8' 1>&2 read -s -d R getsize - echo $getsize | sed 's#..\([0-9]*\);\([0-9]*\)#export LINES=\1 COLUMNS=\2#' + echo $getsize | sed 's#..\([0-9]*\);\([0-9]*\)#LINES=\1 COLUMNS=\2#' } function set_terminal_size () { - eval `get_terminal_size` + eval "export `get_terminal_size`" stty cols $COLUMNS rows $LINES } @@ -1179,10 +1183,10 @@ alias helpm='help_myself' function print_iconv () { [ "$1" = "$2" ] && cat && return 0 - iconv -f "$1" -t "$2" + iconv -f "$1" -t "$2" } -function help_myself () +function help_myself () { echo "argc = $#" echo "argv[0] = $0" @@ -1254,14 +1258,14 @@ function help_function () set_console_title set_terminal_size varset variables ... - unzip_nomac filenames ... + unzip_nomac filenames ... x createdir_askmode dirname x is_file_type filename type [-- sudo_prefix ...] x get_file_size filename [-- sudo_prefix ...] x get_terminal_size x split_arguments [arguments ...] -Obsolete functions are not printed. Type \`help_obsolete' to print them. +Obsolete functions are not printed. Type \`help_obsolete' to print them. ENDHELPMSG } && return 0 local current_charset=`echo "$LC_ALL" | cut -d . -f 2` @@ -1301,9 +1305,9 @@ ENDHELPMSG bgview [number] 顯示以 bgrun 執行指令的輸出,若省略 number,表示是最近一次執行的指令 若 number > 0, - 表示第 number 個指令 (此數值可由 bglist 函式取得) + 表示第 number 個指令 (此數值可由 bglist 函式取得) 若 number <= 0, - 表示第「指令總數-number」個指令 (指令總數可由 bgcount 函式取得) + 表示第「指令總數-number」個指令 (指令總數可由 bgcount 函式取得) ENDHELPMSG ;; bgclean|bgrm) @@ -1339,17 +1343,17 @@ ENDHELPMSG umask 0022 -if [ "$interactive_shell" ] +if [ "$interactive_shell" ] then echo "Running interactive shell configuration" check_important_files startcolor prehistory_backup - bind '"\e[A":history-search-backward' + bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward' if [ -z "$PROMPT_COMMAND" ] && [ -e "$HOME/.bash_title" ]; then case "$TERM" in - xterm*) + xterm*) PROMPT_COMMAND='printf "\033]0;%s@%s:%s (%s)\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}" "`date "+%H:%M:%S"`"' ;; screen*) @@ -1379,7 +1383,7 @@ shopt -s mailwarn [ "$interactive_shell" ] && { echo "Done" - if [ "$UID" = "0" ] || [ "$EUID" = "0" ] + if [ "$UID" = "0" ] || [ "$EUID" = "0" ] then printf "\nNote: You may be \e[1;32mprivileged\e[m now!\n\n" fi @@ -97,4 +97,18 @@ if g:plugins_enabled Bundle 'tkztmk/vim-vala' endif +if has("cscope") + set cst + set csverb + set cscopequickfix=s-,c-,d-,i-,t-,e- + nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR> + nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR> + nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR> + nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR> + nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR> + nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR> + nmap <C-\>i :cs find i <C-R>=expand("<cfile>")<CR>$<CR> + nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR> +endif + "set guifont=Liberation\ Mono\ for\ Powerline\ 11 |