我的.bashrc
對于linux, 相信每個朋友都會有自己的使用習慣. 也會總結出不少的 alias 等等.
下面是我的.bashrc, 希望對對朋友們有借鑒作用.
如果有不明白的, 歡迎隨時交流. :)
export PS2="-> " export PS4='+{$LINENO:${FUNCNAME[0]}}' set -o vi# ignore case bind "set completion-ignore-case on"# do NOT limit the size of core file ulimit -c unlimitedexport PROMPT_COMMAND='echo -ne "\033]0;$PWD\007"'# check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsizebind '"\e[A": history-search-backward' bind '"\e[B": history-search-forward'shopt -s autocd # auto "cd" when entering just a path # ls ## {{{ alias ls='\ls -F --color=auto' alias LS='ls' alias sl='ls' alias s='ls' alias l='ls -lh' alias la='ls -A' alias ll='l -A' alias l.='la -d .*' alias ll.='ll -d .*' alias lr='ls -R' # recursive ls alias lm='la | less' alias lld='__Lld' alias lf='__Lf'alias llta='ll -rt' # sort by date ascent alias llxa='ll -BX' # sort by extension ascent alias llza='ll -rS' # sort by size ascent alias lltd='ll -t' # sort by date descent alias llxd='ll -rBX' # sort by extension descent alias llzd='ll -S' # sort by size descent alias llt='llta' # sort by date (ascent) alias llx='llxa' # sort by extension (ascent) alias llz='llza' # sort by size (ascent)alias lta='l -rt' # sort by date ascent alias lxa='l -BX' # sort by extension ascent alias lza='l -rS' # sort by size ascent alias ltd='l -t' # sort by date descent alias lxd='l -rBX' # sort by extension descent alias lzd='l -S' # sort by size descent alias lt='lta' # sort by date (ascent) alias lx='lxa' # sort by extension (ascent) alias lz='lza' # sort by size (ascent) # }}}## cd ## {{{ alias cd.='' alias cd..='cd ..' alias ..='cd ..' alias ..1='cd ..' alias ..2='cd ../..' alias ..3='cd ../../..' alias ..4='cd ../../../..' alias ..5='cd ../../../../..' alias cd1='..' alias cd2='..2' alias cd3='..3' alias cd4='..4' alias cd5='..5' alias cd-='cd -'alias cn0='__NthPath 0' alias cn1='__NthPath 1' alias cn2='__NthPath 2' alias cn3='__NthPath 3' alias cn4='__NthPath 4' alias cn5='__NthPath 5' alias cn6='__NthPath 6' alias cn7='__NthPath 7' alias cn8='__NthPath 8' alias cn9='__NthPath 9' alias cn='__NthPath ' # }}}alias sudo='sudo '## Modified commands ## {{{ alias diff='colordiff' alias more='less' alias df='df -h' alias du='du -c -h' alias du1='du --max-depth=1' alias du.='du -s .' alias mkdir='mkdir -p' alias nano='nano -w' alias ping='ping -c 3' alias dmesg='dmesg -HL' alias date='date "+%A, %B %d, %Y [%T]"' alias hist='history | grep' # requires an argument alias openports='ss --all --numeric --processes --ipv4 --ipv6' alias pgp='ps -aux | grep ' # requires an argumentalias clr='clear' alias vi='vim' alias g++='g++ -std=c++14 ' alias gg='g++ -std=c++14 -g ' alias cl='clang++ -std=c++14 ' alias clg='clang++ -std=c++14 -g ' #}}}## Privileged access ## {{{ if [ $UID -ne 0 ]; thenalias scat='sudo cat'alias svi='sudo vi'alias root='sudo -s'alias sreboot='sudo systemctl reboot'alias spoweroff='sudo systemctl poweroff'alias snetctl='sudo netctl' fi #}}}## pacman alias ## {{{ alias pacupg='sudo pacman -Syu' # Synchronize with repositories and then upgrade packages that are out of date on the local system. alias pacin='sudo pacman -S' # Install specific package(s) from the repositories alias pacins='sudo pacman -U' # Install specific package not from the repositories but from a file alias pacre='sudo pacman -R' # Remove the specified package(s), retaining its configuration(s) and required dependencies alias pacrem='sudo pacman -Rns' # Remove the specified package(s), its configuration(s) and unneeded dependencies alias pacout='pacrem' alias pacrep='pacman -Si' # Display information about a given package in the repositories alias pacreps='pacman -Ss' # Search for package(s) in the repositories alias pacloc='pacman -Qi' # Display information about a given package in the local database alias paclocs='pacman -Qs' # Search for package(s) in the local database alias paclo="pacman -Qdt" # List all packages which are orphaned alias pacc="sudo pacman -Scc" # Clean cache - delete all not currently installed package files alias paclf="pacman -Ql" # List all files installed by a given package alias pacexpl="pacman -D --asexp" # Mark one or more installed packages as explicitly installed alias pacimpl="pacman -D --asdep" # Mark one or more installed packages as non explicitly installed # '[r]emove [o]rphans' - recursively remove ALL orphaned packages alias pacro="pacman -Qtdq > /dev/null && sudo pacman -Rns \$(pacman -Qtdq | sed -e ':a;N;$!ba;s/\n/ /g')"# Additional pacman alias examples alias pacupd='sudo pacman -Sy && sudo abs' # Update and refresh the local package and ABS databases against repositories alias pacinsd='sudo pacman -S --asdeps' # Install given package(s) as dependencies alias pacmir='sudo pacman -Syy' # Force refresh of all package lists after updating /etc/pacman.d/mirrorlistalias pacunlock="sudo rm /var/lib/pacman/db.lck" # Delete the lock file /var/lib/pacman/db.lck alias paclock="sudo touch /var/lib/pacman/db.lck" # Create the lock file /var/lib/pacman/db.lck #}}}## for myself ## {{{#WM='pantheon-files' #WM='spacefm' WM='thunar' #WM=nautilus #WM=pcmanfmalias o='${WM} ' alias o.='${WM} "${PWD}"' alias so='sudo ${WM} ' alias so.='so "${PWD}"'DL=${HOME}/Downloads DT=${HOME}/Desktop DM=${HOME}/Documentsalias cddl='cd "${DL}"' alias cddt='cd "${DT}"' alias cddm='cd "${DM}"' alias odl='o "${DL}"' alias odt='o "${DT}"' alias odm='o "${DM}"' #}}}# arch offline wiki export wiki_browser=firefox alias ws='wiki-search ' alias wsh='wiki-search-html 'if [ -f ~/.cmd ] then. ~/.cmd__PS1alias grep="$(__Colorized grep)"alias egrep="$(__Colorized egrep)"alias fgrep="$(__Colorized fgrep)" fi以 __ 開頭的是自定義的函數, 在另一個文件(.cmd) 中
這個文件中, 名稱為小寫的是 直接可以在命令行中調用的, 比如 proxy, 可以直接設置代理
而以__開頭的大寫函數, 則是為了讓其它指令或者別名調用, 不推薦在shell中直接調用(這也是取這么難寫名字的原因)
function __PS1() {local normalColor="\[\e[38;5;22m\]"local urgentColor="\[\e[0;31m\]"local pathColor="\[\e[1;34m\]"local endColor="\[\e[m\]"local tip='\$ 'local good="${normalColor}${tip}${endColor}"local bad="${urgentColor}${tip}${endColor}"local path=${pathColor}'\w '${endColor}local colorizedTip="\$(if [[ \$? == 0 ]]; then echo \"${good}\"; else echo \"${bad}\"; fi)"export PS1=${path}${colorizedTip} }function __Colorized() {[ -n "$1" ] && echo "$1 --color=auto" }function mkcd() {mkdir -p "$@" && eval cd "\"\$$#\""; }function __NthPath() {[ $1 -eq 0 ] && cd / && return 0cd "$(echo "${PWD}" | cut -d / -f -$(($1 + 1)))" }function cdls() {local dir=$1if [[ -z "${dir}" ]]thendir=${HOME}fiif [[ -d "${dir}" ]]thencd "${dir}"lselseecho "bash: cdls: '${dir}': Directory not found"fi }function __CreateNotesIfNotExist() {if [[ $# -eq 1 && ! -f $1 ]]thentouch $1fi }function note() {file="${HOME}/.${FUNCNAME}"# if file doesn't exist, create it__CreateNotesIfNotExist ${file}if ! (($#))then# no arguments, print filecat "${file}"elif [[ "$1" == "-c" ]]then# clear file> "${file}"else# add all arguments to fileprintf "%s\n" "$*" >> "${file}"fi }function todo() {file="${HOME}/.${FUNCNAME}"# if file doesn't exist, create it__CreateNotesIfNotExist ${file}if ! (($#));thencat "${file}"elif [[ "$1" == "-l" ]]thennl -b a "${file}"elif [[ "$1" == "-c" ]]then> ${file}elif [[ "$1" == "-r" ]]thennl -b a "${file}"printf "----------------------------\n"read -p "Type a number to remove: " numberex -sc "${number}d" "${file}"elseprintf "%s\n" "$*" >> "${file}"fi }function calc() {echo "scale=3;$@" | bc -l }function __Proxy() {export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"local proxy=$1if [ $# -eq 0 ]thenproxy="3.36.125.228:9400"fiexport http_proxy=${proxy}export https_proxy=${http_proxy}export ftp_proxy=${http_proxy}export rsync_proxy=${http_proxy}echo "proxy environment variable set." }function proxy() {local proxy=" " ##### default proxyif [ $# -eq 1 ]thenproxy=${1}fi__Proxy "${proxy}" }function proxyoff() {unset http_proxyunset https_proxyunset ftp_proxyunset rsync_proxyecho -e "proxy environment variable removed." }function __Lf() {if [[ $# -eq 0 ]]thenl | grep ^[^d] | awk '{print $NF}'elsel -d "$@"fi }function __Lld() {if [[ $# -eq 0 ]]thenl | grep ^[d] | awk '{print $NF}'elsel -d "$@"fi }轉載于:https://www.cnblogs.com/typename/p/4654873.html
總結
- 上一篇: 数据结构之线性表(附代码)
- 下一篇: 计算机网络之应用层:2、DNS域名解析系