Revamp sync script, fix -s flag

This commit is contained in:
Austen Adler 2017-11-27 11:45:01 -05:00
parent 9f687529b8
commit 576b7af65f
4 changed files with 147 additions and 157 deletions

View File

@ -1,9 +1,3 @@
[user]
name = Austen Adler
email = stonewareslord@gmail.com
#signingkey = CCDFE3F1
[commit]
#gpgsign=true
[alias] [alias]
i = "!git br&&git st" i = "!git br&&git st"
# coa = "!for i in $(git branch -a|cut -b3-|grep remotes|sed -e 's/remotes\///'|cut -d/ -f1 --complement|cut -d\ -f1);do git checkout $i;done" # coa = "!for i in $(git branch -a|cut -b3-|grep remotes|sed -e 's/remotes\///'|cut -d/ -f1 --complement|cut -d\ -f1);do git checkout $i;done"

View File

@ -1,84 +1,126 @@
ABSPATH=$(\cd "$(dirname "$0")/.."; pwd) #!/bin/bash
echo $ABSPATH ABSPATH="$(\pushd >/dev/null "$(\dirname "$0")/..";\pwd;\popd >/dev/null)"
while getopts ":shbc" VALUE "$@"; do SYNC_CONFIG=0
if [ "$VALUE" = "h" ] ; then SHOW_HELP=0
echo "sync.sh syncs configuration files, applications, and Vim bundles between computers" SYNC_CUSTOM=0
echo " -h Shows this help" SYNC_VIM=0
echo " -b Syncs Vim bundles" VALID_CMD=0
echo " -s Use this if you don't want custom stonewareslord settings (use after -s)" RECLONE=0
echo " -c Sync configuration files" TMP_PATH="/tmp/$(uuidgen)"
fi mkdir -p "$TMP_PATH"
if [ "$VALUE" = "s" ] ; then sync_config() {
sed -i'' -e '/email = stonewareslord@gmail.com/d' -e '/user = Austen Adler/d' -e '/\[user\]/d' -e '/signingkey = CCDFE3F1/d' ~/.gitconfig # Remove old config files
fi remove ~/.gitconfig ~/.bashrc ~/.pylintrc ~/.zsh ~/.zshrc ~/.tmux.conf ~/.config/liquidpromptrc ~/.config/dunstrc
if [ "$VALUE" = "b" ] ; then # Silently remove vimperator files since we are not reinstalling
trash ~/.vimrc || rm ~/.vimrc remove -s ~/.vimperatorrc ~/.vimperator/colors/vimPgray.vimp
ln -s $ABSPATH/vim/vimrc ~/.vimrc if [[ $RECLONE = 1 ]]; then
vim +"silent! call Initialize()" +q remove ~/.fzf ~/.zsh-git
fi
if [ "$VALUE" = "c" ] ; then
if [ "$2" = "-f" ] ; then
# Reinstall antigen
rm -rf ~/.antigen
fi
echo "Syncing config files"
if command -v trash 2>&1 /dev/null; then
trash ~/.gitconfig ~/.vimperatorrc ~/.vimperator/colors/vimPgray.vimp ~/.bashrc ~/.pylintrc ~/.zsh ~/.zshrc ~/.tmux.conf ~/.config/liquidpromptrc ~/.config/dunstrc
else
rm ~/.gitconfig ~/.vimperatorrc ~/.vimperator/colors/vimPgray.vimp ~/.bashrc ~/.pylintrc ~/.zsh ~/.zshrc ~/.tmux.conf ~/.config/liquidpromptrc ~/.config/dunstrc
fi fi
# Install on all systems # Install on all systems
ln -s $ABSPATH/dunst/dunstrc ~/.config/dunstrc # Vimperator has perished. Don't install vimperator files anymore
ln -s $ABSPATH/tmux/tmux.conf ~/.tmux.conf #ln -s "$ABSPATH/vimperator/vimperatorrc" ~/.vimperatorrc
ln -s $ABSPATH/python/pylintrc ~/.pylintrc #mkdir -p ~/.vimperator/colors
ln -s $ABSPATH/vimperator/vimperatorrc ~/.vimperatorrc #ln -s "$ABSPATH/vimperator/vimPgray.vimp" ~/.vimperator/colors/vimPgray.vimp
mkdir -p ~/.vimperator/colors
ln -s $ABSPATH/vimperator/vimPgray.vimp ~/.vimperator/colors/vimPgray.vimp
ln -s $ABSPATH/git/gitconfig ~/.gitconfig
ln -s $ABSPATH/shells/bashrc ~/.bashrc
ln -s $ABSPATH/zsh ~/.zsh
if command -v git 2>&1 >/dev/null; then if command -v git 2>&1 >/dev/null; then
if command -v zsh 2>&1 >/dev/null; then if command -v zsh 2>&1 >/dev/null; then
ln -s $ABSPATH/shells/zshrc ~/.zshrc
for i in lpr oh-my-git-themes omg zsh-syntax-highlighting; do for i in lpr oh-my-git-themes omg zsh-syntax-highlighting; do
if [ ! -d ~/.zsh-git/$i ]; then if [ ! -d ~/.zsh-git/"$i" ]; then
git clone https://austenwares.com/gitea/stonewareslord/$i.git ~/.zsh-git/$i git clone "https://austenwares.com/gitea/stonewareslord/$i.git" ~/.zsh-git/"$i"
else
\cd ~/.zsh-git/$i
git pull
\cd -
fi fi
done done
fi fi
if [ ! -d ~/.fzf ] ; then if [ ! -d ~/.fzf ] ; then
git clone https://austenwares.com/gitea/stonewareslord/fzf.git ~/.fzf git clone "https://austenwares.com/gitea/stonewareslord/fzf.git" ~/.fzf
~/.fzf/install -y ~/.fzf/install --bin
fi fi
else else
echo "No git! Not installing fzf or antigen" echo "No git! Not installing fzf or zsh packages"
fi fi
mkdir -p ~/.config mkdir -p ~/.config
ln -s $ABSPATH/shells/liquidpromptrc ~/.config/liquidpromptrc ln -s "$ABSPATH/dunst/dunstrc" ~/.config/dunstrc
ln -s "$ABSPATH/tmux/tmux.conf" ~/.tmux.conf
ln -s "$ABSPATH/python/pylintrc" ~/.pylintrc
ln -s "$ABSPATH/git/gitconfig" ~/.gitconfig
ln -s "$ABSPATH/shells/bashrc" ~/.bashrc
ln -s "$ABSPATH/shells/zshrc" ~/.zshrc
ln -s "$ABSPATH/zsh" ~/.zsh
ln -s "$ABSPATH/shells/liquidpromptrc" ~/.config/liquidpromptrc
if [ "$(uname)" != "Darwin" ]; then if [ "$(uname)" != "Darwin" ]; then
if command -v trash 2>&1 >/dev/null; then
trash ~/.i3/{config,i3status.conf,run.sh} ~/.Xmodmap ~/.xsession ~/.config/synapse/gtkrc ~/.Xresources
else
rm ~/.i3/{config,i3status.conf,run.sh} ~/.Xmodmap ~/.xsession ~/.config/synapse/gtkrc ~/.Xresources
fi
# Don't install these on Mac # Don't install these on Mac
mkdir -p ~/.i3 remove ~/.i3/{config,i3status.conf,run.sh} ~/.Xmodmap ~/.xsession ~/.config/synapse/gtkrc ~/.Xresources
ln -s $ABSPATH/i3/config ~/.i3/config mkdir -p ~/.i3 ~/.config/synapse
ln -s $ABSPATH/i3/$(hostname)-status.conf ~/.i3/i3status.conf 2>/dev/null ln -s "$ABSPATH/i3/config" ~/.i3/config
ln -s $ABSPATH/i3/run.sh ~/.i3/run.sh ln -s "$ABSPATH/i3/$(hostname)-status.conf" ~/.i3/i3status.conf 2>/dev/null
ln -s $ABSPATH/i3/Xmodmap ~/.Xmodmap ln -s "$ABSPATH/i3/run.sh" ~/.i3/run.sh
ln -s $ABSPATH/i3/xsession ~/.xsession ln -s "$ABSPATH/i3/Xmodmap" ~/.Xmodmap
mkdir -p ~/.config/synapse ln -s "$ABSPATH/i3/xsession" ~/.xsession
ln -s $ABSPATH/i3/gtkrc ~/.config/synapse/gtkrc ln -s "$ABSPATH/i3/gtkrc" ~/.config/synapse/gtkrc
ln -s $ABSPATH/shells/Xresources ~/.Xresources ln -s "$ABSPATH/shells/Xresources" ~/.Xresources
if command -v xrdb 2>&1 >/dev/null; then if command -v xrdb 2>&1 >/dev/null; then
xrdb ~/.Xresources xrdb ~/.Xresources
fi fi
fi fi
}
sync_custom() {
if ! command -v git 2>&1 >/dev/null; then
echo "Error! No git -- can't sync custom files"
exit
fi fi
if [[ ! -d ~/.zsh-git/custom-config ]]; then
#TODO: Figure out if I should use ssh or https cloning
#git clone https://austenwares.com/gitea/stonewareslord/custom-config
git clone git@austenwares.com:stonewareslord/custom-config ~/.zsh-git/custom-config
fi
remove ~/.gitconfig
ln -s ~/.zsh-git/custom-config/gitconfig ~/.gitconfig
# Custom zsh is sourced from zshrc
}
sync_vim() {
remove ~/.vimrc
ln -s "$ABSPATH/vim/vimrc" ~/.vimrc
vim +"silent! call Initialize()" +q
}
show_help() {
echo "sync.sh syncs configuration files and Vim plugins on computers"
echo " -h Shows this help"
echo " -b Syncs Vim bundles"
echo " -s Use this if you want custom stonewareslord settings"
echo " -c Sync configuration files"
echo " -r Reclone all git repositories"
exit
}
remove() {
local SILENT=0
if [[ "$1" = "-s" ]]; then
# Be quiet!
SILENT=1
fi
if [[ $SILENT = 1 ]]; then
\mv -t "$TMP_PATH" $* 2>/dev/null
else
\mv -t "$TMP_PATH" $*
fi
}
while getopts ":shbc" OPT "$@"; do
case $OPT in
b) SYNC_VIM=1;VALID_CMD=1;;
s) SYNC_CUSTOM=1;;
c) SYNC_CONFIG=1;VALID_CMD=1;;
r) RECLONE=1;;
*) SHOW_HELP=1;;
esac
done done
if [[ $SHOW_HELP = 1 ]] || [[ ! $VALID_CMD = 1 ]]; then
show_help
fi
echo "Syncing config files. Placing old files in $TMP_PATH"
if [[ $SYNC_CONFIG = 1 ]]; then
sync_config
if [[ $SYNC_CUSTOM = 1 ]]; then
sync_custom
fi
fi
if [[ $SYNC_VIM = 1 ]]; then
sync_vim
fi
echo "Done syncing" echo "Done syncing"

View File

@ -1,8 +1,6 @@
# Borg backup repository
export BORG_REPO="aw:borg"
#zmodload zsh/zprof #zmodload zsh/zprof
echo -ne '[ ]\r' echo -ne '[ ]\r'
for config (~/.zsh/*.zsh) source $config for CONFIG (~/.zsh/*.zsh) source "$CONFIG"
autoload -U compinit autoload -U compinit
compinit compinit
setopt always_to_end # When completing from the middle of a word, move the cursor to the end of the word setopt always_to_end # When completing from the middle of a word, move the cursor to the end of the word
@ -13,7 +11,7 @@ setopt HIST_EXPIRE_DUPS_FIRST
export HIST_STAMPS="dd.mm.yyyy" export HIST_STAMPS="dd.mm.yyyy"
export HISTSIZE=12000 export HISTSIZE=12000
export SAVEHIST=10000000 export SAVEHIST=10000000
export HISTFILE=$HOME/.zsh_history export HISTFILE="$HOME/.zsh_history"
setopt APPEND_HISTORY setopt APPEND_HISTORY
setopt EXTENDED_HISTORY setopt EXTENDED_HISTORY
setopt APPEND_HISTORY SHARE_HISTORY HISTIGNOREALLDUPS setopt APPEND_HISTORY SHARE_HISTORY HISTIGNOREALLDUPS
@ -515,20 +513,6 @@ hsh(){
echo pv "$FILE" \| pee $ARGS echo pv "$FILE" \| pee $ARGS
pv "$FILE" | pee $(echo $ARGS) pv "$FILE" | pee $(echo $ARGS)
} }
enc() {
test -f README.md || echo "# enc\n## files" > README.md
while (( $# > 0 )) ; do
fn="$1"
uuid="$(uuidgen)"
shift
echo "Encrypting ($fn)..."
pv "$fn" | gpg -r stonewareslord -o "$uuid" -e - || (echo "Error encrypting $fn" >&2 ; continue)
echo "- \`$uuid\`: \`$fn\`" >> README.md || (echo "Error appending $fn to README.md" >&2 ; continue)
echo "Calculating sum of ($fn) in the background"
pv "$uuid" | sha512sum | perl -pe "s/-/$uuid/" >> SHA512SUMS || (echo "Error calculating sum of $uuid" >&2 ; continue)
rm "$fn" || (echo "Error removing $fn"; continue)
done
}
rc(){ rc(){
case $1 in case $1 in
z) vim ~/.zshrc;; z) vim ~/.zshrc;;
@ -544,19 +528,6 @@ rc(){
*) echo "Opts:\nz v i\nuse make unmask mask accept_keywords keywords license" *) echo "Opts:\nz v i\nuse make unmask mask accept_keywords keywords license"
esac esac
} }
pub-git-init(){
# Get the project name
branch=$(git remote -v | ag '^origin\s+' | sed -e 's/^origin\s*//' | cut -d\ -f1 | sed -r -e 's/^.+\///' -e 's/#.+$//' -e 's/\.git$//' | head -n1)
echo "Branch: $branch"
# Get the hashed project name
enc_branch=$(echo "$branch" | sha512sum | cut -d\ -f1)
git remote add local "gcrypt::git@localhost:stonewareslord/79a79b1a6e37813d9226872c6428aca29eec9f6111558109861cb0dcd2f0ffc8198deea4e361f84e170989212452fdfb21e0ef690da2ad399c03ce308d79dcfe#$enc_branch"
git remote add ncsu "gcrypt::git@github.ncsu.edu:agadler/a86a0f8757772be2ec617b395a0716679bfce51c1bfdeb8da6127feebd84facde645e9e30188318344eb458f5834e3d86800.git#$enc_branch"
git remote add gitlab "gcrypt::git@gitlab.com:stonewareslord/e6e03ea006d55de0970a28bcb7fcf65f4c66f98f50830bd69b50c5dc502bdf1a4e4172187cfb5fcef8c32bd7fb316bdc67d7d86713ebfe232f97eb303ac316ae.git#$enc_branch"
git remote add aws "gcrypt::git@aws:stonewareslord/5e0701d5b5b2118127d378c084be9a1dfb33d185d3e2c5da30a3984f5118e3d5136f3f3b038462bccd538e93f9e32cb06136.git#$enc_branch"
git config remote.ncsu.gcrypt-participants "CCDFE3F1"
git config remote.gitlab.gcrypt-participants "CCDFE3F1"
}
pub-git-rm(){ pub-git-rm(){
if (( $# == 0 )) ; then if (( $# == 0 )) ; then
git remote rm local git remote rm local
@ -581,22 +552,6 @@ pub-git-push(){
shift shift
done done
} }
pub-git-clone(){
case $1 in
ncsu) remote="gcrypt::git@github.ncsu.edu:agadler/a86a0f8757772be2ec617b395a0716679bfce51c1bfdeb8da6127feebd84facde645e9e30188318344eb458f5834e3d86800.git#" ;;
gitlab) remote="gcrypt::git@gitlab.com:stonewareslord/e6e03ea006d55de0970a28bcb7fcf65f4c66f98f50830bd69b50c5dc502bdf1a4e4172187cfb5fcef8c32bd7fb316bdc67d7d86713ebfe232f97eb303ac316ae.git#" ;;
local) remote="gcrypt::git@localhost:stonewareslord/79a79b1a6e37813d9226872c6428aca29eec9f6111558109861cb0dcd2f0ffc8198deea4e361f84e170989212452fdfb21e0ef690da2ad399c03ce308d79dcfe#" ;;
aws) remote="gcrypt::git@aws:stonewareslord/5e0701d5b5b2118127d378c084be9a1dfb33d185d3e2c5da30a3984f5118e3d5136f3f3b038462bccd538e93f9e32cb06136.git#" ;;
*) echo "Opts: local ncsu gitlab" ; return 1
esac
shift
if [ -z "$1" ] ; then
echo "No arg2"
return 2
fi
branch=$(echo $1 | sha512sum | cut -d\ -f1)
git clone "$remote$branch" $1
}
k(){ k(){
#More than 1 arguement #More than 1 arguement
if [[ $# > 1 ]] ; then if [[ $# > 1 ]] ; then
@ -669,5 +624,8 @@ source ~/.zsh-git/lpr/liquidprompt
source ~/.zsh-git/omg/base.sh source ~/.zsh-git/omg/base.sh
source ~/.zsh-git/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source ~/.zsh-git/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source ~/.zsh-git/oh-my-git-themes/af-magic.zsh-theme source ~/.zsh-git/oh-my-git-themes/af-magic.zsh-theme
if [[ -f ~/.zsh-git/zshrc ]]; then
source ~/.zsh-git/zshrc
fi
echo -e '[##]' echo -e '[##]'
#zprof #zprof

View File

@ -374,7 +374,6 @@ endif
silent! colorscheme fruity silent! colorscheme fruity
function! Initialize() function! Initialize()
if has("win32") if has("win32")
if empty(glob("~/_vim/autoload/plug.vim"))
cd ~ cd ~
silent !mkdir vimfiles silent !mkdir vimfiles
cd vimfiles cd vimfiles
@ -386,11 +385,7 @@ function! Initialize()
cd autoload cd autoload
silent !powershell -command "& { iwr https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -OutFile plug.vim }" silent !powershell -command "& { iwr https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -OutFile plug.vim }"
silent! so ~/_vimrc silent! so ~/_vimrc
silent! PlugInstall
q
endif
else else
if empty(glob("~/.vim/autoload/plug.vim"))
silent !mkdir -p ~/.vim/autoload silent !mkdir -p ~/.vim/autoload
silent !mkdir -p ~/.vim/plugin silent !mkdir -p ~/.vim/plugin
silent !mkdir -p ~/.vim/backup silent !mkdir -p ~/.vim/backup
@ -398,10 +393,11 @@ function! Initialize()
silent !mkdir -p ~/.vim/tmp silent !mkdir -p ~/.vim/tmp
silent !curl -fLo ~/.vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim silent !curl -fLo ~/.vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
silent! so ~/.vimrc silent! so ~/.vimrc
endif
silent! PlugClean!
silent! PlugUpdate
silent! PlugInstall silent! PlugInstall
q q
endif
endif
endfunction endfunction
if !exists('g:ycm_semantic_triggers') if !exists('g:ycm_semantic_triggers')
let g:ycm_semantic_triggers = {} let g:ycm_semantic_triggers = {}