使用stow来管理dotfiles

使用stow来配置好自己的dotfile,这样无论在哪台终端机上都能快速恢复自己习惯的配置

终端用户的点文件非常的多,zshrc,bashrc,config之类之类。

这样可以利用stow这个工具来对常用的点文件进行管理。

stow的作用是把当前文件夹中的目标文件或文件夹 在其上级目录中建立其相应的符号链接。

而实际上所有被管理的dot文件都放在一个文件夹内方便自己的配置和管理。

比如,我的dotfile文件夹在/home/binbla/dotfiles
– 进入该文件夹
cd /home/binbla/dotfiles
– 恢复我的zsh相关配置
stow zsh
这样就会在/home/binbla/下建立到/home/binbla/dotfiles/zsh/.zshrc/home/binbla/dotfiles/zsh/.zshrc-alias的符号链接
– 恢复我的bash相关配置
stow bash
– 恢复我的vim相关配置
stow vim

详细的目录结构可参考这里

.zshrc

#git stow zsh og-my-zsh-git powerline ranger exa zsh-autosuggestions zsh-syntax-highlighting zsh-history-substring-search
export ZSH="/usr/share/oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(git)
source ZSH/oh-my-zsh.sh
alias zshconfig=". ~/.zshrc"
alias ohmyzsh=". ~/.oh-my-zsh"
export EDITOR='vim'
export VISUAL='vim'

#用户二进制程序目录
if [ -d "HOME/.bin" ] ;
  then PATH="HOME/.bin:PATH"
fi

if [ -d "HOME/.local/bin" ] ;
  then PATH="HOME/.local/bin:PATH"
fi

# 自动补全
autoload -U compinit promptinit
compinit
promptinit
setopt autocd extendedglob
unsetopt beep
bindkey -v

# 启动使用方向键控制的自动补全
zstyle ':completion:*' menu select

# 按两次 tab 键启动菜单
setopt completealiases

# 配置提示符
# 使用主题
# prompt bart
# 使用自定义配置
if [ `whoami` = "root" ];then usign='#';else usign='';fi
PROMPT="%{fg[green]%}[%{reset_color%}%{fg[red]%}%n%{reset_color%}@%{fg[blue]%}%m %{fg[yellow]%}%1~ %{reset_color%}%{fg[green]%}] %{reset_color%}{usign} "
RPROMPT="%{fg[green]%}%T%{reset_color%} [%{fg[yellow]%}%?%{reset_color%}]"
unset usign
# 说明
# %T    系统时间(时:分)
# %*    系统时间(时:分:秒)
# %D    系统日期(年-月-日)
# %n    你的用户名
# %B - %b   开始到结束使用粗体打印
# %U - %u   开始到结束使用下划线打印
# %d    你目前的工作目录
# %~    你目前的工作目录相对于~的相对路径(可能在某些zsh版本可能造成乱码)
# %M    计算机的主机名
# %m    计算机的主机名(在第一个句号之前截断)
# %l  当前tty

# 自动更新path中可执行程序
zstyle ':completion:*' rehash true

#仿fish高亮
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

#POWERLINE
#POWERLINE_BINDINGS=/usr/share/powerline/bindings/
#powerline-daemon -q  # run powerline daemon
#source POWERLINE_BINDINGS/zsh/powerline.zsh

export ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd history completion)
export ZSH_AUTOSUGGEST_USE_ASYNC=true
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh

function zsh_stats() {
  fc -l 1 | awk '{CMD[2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n20
}

function ranger-cd {
    tempfile="(mktemp)"
    /usr/bin/ranger --choosedir="tempfile" "{@:-(pwd)}"
    test -f "tempfile" &&
    if [ "(cat -- "tempfile")" != "(echo -n `pwd`)" ]; then
        cd -- "(cat "tempfile")"
    fi
    rm -f -- "tempfile"
}

#fish高亮
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

#将alias单独放在一起
[ -fHOME/.zshrc-alias ] && source $HOME/.zshrc-alias

#逼格
neofetch

.zshrc_alias

#awesome-configure-test
alias show="Xephyr -ac -br -noreset -screen 1600x900 :1 &;sleep 1;DISPLAY=:1.0 awesome"
#cmatrix换个颜色
alias cmc='cmatrix -b -C cyan -u 5'

#list
alias ls='ls --color=auto'
alias la='ls -a'
alias ll='ls -la'
alias l='ls'
alias l.="ls -A | egrep '^\.'"

#fix obvious typo's
alias cd..='cd ..'
alias pdw="pwd"
alias udpate='sudo pacman -Syyu'
alias upate='sudo pacman -Syyu'
alias updte='sudo pacman -Syyu'
alias updqte='sudo pacman -Syyu'
alias upqll="yay -Syu --noconfirm"
alias upal="yay -Syu --noconfirm"

## Colorize the grep command output for ease of use (good for log files)##
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'

#readable output
alias df='df -h'

#pacman unlock
alias unlock="sudo rm /var/lib/pacman/db.lck"
alias rmpacmanlock="sudo rm /var/lib/pacman/db.lck"

#arcolinux logout unlock
alias rmlogoutlock="sudo rm /tmp/arcologout.lock"

#free
alias free="free -mt"

#use all cores
alias uac="sh ~/.bin/main/000*"

#continue download
alias wget="wget -c"

#userlist
alias userlist="cut -d: -f1 /etc/passwd"

#merge new settings
alias merge="xrdb -merge ~/.Xresources"

# Aliases for software managment
# pacman or pm
alias pacman='sudo pacman --color auto'
alias update='sudo pacman -Syyu'
alias lsp='sudo pacman -Syu'
alias pacwoman='yay -Syu'
alias syu='yay -Syu'

# yay as aur helper - updates everything
alias pksyua="yay -Syu --noconfirm"
alias upall="yay -Syu --noconfirm"

#ps
alias psa="ps auxf"
alias psgrep="ps aux | grep -v grep | grep -i -e VSZ -e"

#grub update
alias update-grub="sudo grub-mkconfig -o /boot/grub/grub.cfg"

#add new fonts
alias update-fc='sudo fc-cache -fv'

#copy/paste all content of /etc/skel over to home folder - backup of config created - beware
alias skel='cp -Rf ~/.config ~/.config-backup-(date +%Y.%m.%d-%H.%M.%S) && cp -rf /etc/skel/* ~'
#backup contents of /etc/skel to hidden backup folder in home/user
alias bupskel='cp -Rf /etc/skel ~/.skel-backup-(date +%Y.%m.%d-%H.%M.%S)'

#copy bashrc-latest over on bashrc - cb= copy bashrc
alias cb='sudo cp /etc/skel/.bashrc ~/.bashrc && source ~/.bashrc'
#copy /etc/skel/.zshrc over on ~/.zshrc - cb= copy zshrc
#alias cz='sudo cp /etc/skel/.zshrc ~/.zshrc && exec zsh'

#switch between bash and zsh
alias tobash="sudo chsh USER -s /bin/bash && echo 'Now log out.'"
alias tozsh="sudo chshUSER -s /bin/zsh && echo 'Now log out.'"

#switch between lightdm and sddm
#alias tolightdm="sudo pacman -S lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings --noconfirm --needed ; sudo systemctl enable lightdm.service -f ; echo 'Lightm is active - reboot now'"
#alias tosddm="sudo pacman -S sddm --noconfirm --needed ; sudo systemctl enable sddm.service -f ; echo 'Sddm is active - reboot now'"

#quickly kill conkies
alias kc='killall conky'

#hardware info --short
alias hw="hwinfo --short"

#skip integrity check
alias yayskip='yay -S --mflags --skipinteg'
alias trizenskip='trizen -S --skipinteg'

#check vulnerabilities microcode
alias microcode='grep . /sys/devices/system/cpu/vulnerabilities/*'

#get fastest mirrors in your neighborhood
alias mirror="sudo reflector -f 30 -l 30 --number 10 --verbose --save /etc/pacman.d/mirrorlist"
alias mirrord="sudo reflector --latest 30 --number 10 --sort delay --save /etc/pacman.d/mirrorlist"
alias mirrors="sudo reflector --latest 30 --number 10 --sort score --save /etc/pacman.d/mirrorlist"
alias mirrora="sudo reflector --latest 30 --number 10 --sort age --save /etc/pacman.d/mirrorlist"
#our experimental - best option for the moment
alias mirrorx="sudo reflector --age 6 --latest 20  --fastest 20 --threads 5 --sort rate --protocol https --save /etc/pacman.d/mirrorlist"
alias mirrorxx="sudo reflector --age 6 --latest 20  --fastest 20 --threads 20 --sort rate --protocol https --save /etc/pacman.d/mirrorlist"

#mounting the folder Public for exchange between host and guest on virtualbox
alias vbm="sudo /usr/local/bin/arcolinux-vbox-share"

#Recent Installed Packages
alias rip="expac --timefmt='%Y-%m-%d %T' '%l\t%n %v' | sort | tail -200 | nl"
alias riplong="expac --timefmt='%Y-%m-%d %T' '%l\t%n %v' | sort | tail -3000 | nl"

#iso and version used to install ArcoLinux
alias iso="cat /etc/dev-rel | awk -F '=' '/ISO/ {print 2}'"

#Cleanup orphaned packages
alias cleanup='sudo pacman -Rns(pacman -Qtdq)'

#search content with ripgrep
alias rg="rg --sort path"

#get the error messages from journalctl
alias jctl="journalctl -p 3 -xb"

#know what you do in these files
alias nlightdm="sudo EDITOR /etc/lightdm/lightdm.conf"
alias npacman="sudoEDITOR /etc/pacman.conf"
alias ngrub="sudo EDITOR /etc/default/grub"
alias nconfgrub="sudoEDITOR /boot/grub/grub.cfg"
alias nmkinitcpio="sudo EDITOR /etc/mkinitcpio.conf"
alias nmirrorlist="sudoEDITOR /etc/pacman.d/mirrorlist"
alias nsddm="sudo EDITOR /etc/sddm.conf"
alias nfstab="sudoEDITOR /etc/fstab"
alias nnsswitch="sudo EDITOR /etc/nsswitch.conf"
alias nsamba="sudoEDITOR /etc/samba/smb.conf"
alias nb="EDITOR ~/.bashrc"
alias nz="EDITOR ~/.zshrc"

#gpg
#verify signature for isos
alias gpg-check="gpg2 --keyserver-options auto-key-retrieve --verify"
alias fix-gpg-check="gpg2 --keyserver-options auto-key-retrieve --verify"
#receive the key of a developer
alias gpg-retrieve="gpg2 --keyserver-options auto-key-retrieve --receive-keys"
alias fix-gpg-retrieve="gpg2 --keyserver-options auto-key-retrieve --receive-keys"
alias fix-key="[ -d ~/.gnupg ] || mkdir ~/.gnupg ; cp /etc/pacman.d/gnupg/gpg.conf ~/.gnupg/ ; echo 'done'"

# # ex = EXtractor for all kinds of archives
# # usage: ex <file>

ex ()
{
  if [ -f 1 ] ; then
    case1 in
      *.tar.bz2)   tar xjf 1   ;;
      *.tar.gz)    tar xzf1   ;;
      *.bz2)       bunzip2 1   ;;
      *.rar)       unrar x1   ;;
      *.gz)        gunzip 1    ;;
      *.tar)       tar xf1    ;;
      *.tbz2)      tar xjf 1   ;;
      *.tgz)       tar xzf1   ;;
      *.zip)       unzip 1     ;;
      *.Z)         uncompress1;;
      *.7z)        7z x 1      ;;
      *.deb)       ar x1      ;;
      *.tar.xz)    tar xf 1    ;;
      *.tar.zst)   tar xf1    ;;
      *)           echo "'1' cannot be extracted via ex()" ;;
    esac
  else
    echo "'1' is not a valid file"
  fi
}

#shutdown or reboot
alias ssn="sudo shutdown now"
alias sr="sudo reboot"

#give the list of all installed desktops - xsessions desktops
alias xd="ls /usr/share/xsessions"

# Set proxy to the system console
socks5ProxyPort=20170
httpProxyPort=20171
httpProxyPortx=20172
#alias setproxy="export ALL_PROXY=socks5://127.0.0.1:{socks5ProxyPort}"
alias setproxy="export ALL_PROXY=http://localhost:{httpProxyPortx}"
alias unsetproxy="unset ALL_PROXY"

# 帮助命令
autoload -U run-help
autoload run-help-git
autoload run-help-svn
autoload run-help-svk
#unalias run-help
alias help=run-help

# optimus-manager
alias intel="optimus-manager --switch integrated"
alias nvidia="optimux-manager --switch nvidia"
alias hybrid="optimus-manager --switch hybrid"

Leave a Comment

您的电子邮箱地址不会被公开。 必填项已用 * 标注