Cleanup a bunch of scripts and add an installer script

This commit is contained in:
Tony Blyler 2019-12-06 16:31:10 -05:00
parent add685765d
commit 52b0cb0d84
14 changed files with 382 additions and 99 deletions

View file

@ -10,6 +10,13 @@ function GoPostUpdate()
:GoUpdateBinaries
endfunction
" automatically install vim-plug if it doesn't exist
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin($HOME.'/.nvim/plugged')
if s:uname == "Linux"

View file

@ -1,19 +0,0 @@
# auto install oh-my-zsh and tpm
if which git > /dev/null 2>&1; then
# if oh-my-zsh is not installed, autoinstall it
if [ ! -e "${ZSH}" ]; then
echo 'oh-my-zsh is missing... autoinstalling now'
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
fi
local TPM="${HOME}/.tmux/plugins/tpm"
# if tpm (Tmux Plugin Manager) is not installed, autoinstall it
if [ ! -e "${TPM}" ]; then
git clone https://github.com/tmux-plugins/tpm "${TPM}"
fi
if ! egrep -q 'run.*tpm' "${HOME}/.tmux.conf" 2>&1; then
echo 'adding TPM to ~/.tmux.conf'
echo "run '${HOME}/.tmux/plugins/tpm/tpm'" >> "${HOME}/.tmux.conf"
fi
fi

View file

@ -1,34 +0,0 @@
# fup uploads a given file to file.io
fup() {
if [ -z "${1}" -o ! -f "${1}" ]; then
echo 'provide a valid file path'
return 1
fi
local cmd="-F 'file=@${1}' https://file.io/"
if [ ! -z "${2}" ]; then
cmd="${cmd}\?expires=${2}"
fi
local json_return="$(eval "curl ${cmd}")"
if [ $? -ne 0 ]; then
echo 'Curl failed'
return 1
fi
if [ $(echo "${json_return}" | grep -c '"success":false') -ne 0 ]; then
echo "${json_return}"
return 1
fi
echo "https://file.io/$(echo "${json_return}" | sed 's/.*key":"//' | sed 's/".*//')"
if [ $(echo "${json_return}" | grep -c '"expiry":') -eq 0 ]; then
echo 'Expires in 14 days'
else
echo "Expires in $(echo "${json_return}" | sed 's/.*expiry":"//' | sed 's/".*//')"
fi
return 0
}

View file

@ -1,26 +0,0 @@
note() {
local DATE="$(date '+%s')"
local BASE_NOTE_PATH="${NOTE_PATH:-$(pwd)}"
local IS_DATE_PATH=1
if [[ "${1}" =~ '^ *[-+]{0,1}[0-9]+ *$' ]]; then
local DAY=86400
local DATE=$(( DATE + (DAY * ${1}) ))
elif [[ -n "${1}" ]]; then
local IS_DATE_PATH=''
local NOTE_PATH="${BASE_NOTE_PATH}/${1}"
if ! [[ "${1}" =~ '\.[mM][dD]$' ]]; then
local NOTE_PATH="${NOTE_PATH}.md"
fi
fi
if [[ ${IS_DATE_PATH} ]]; then
local NOTE_PATH="${BASE_NOTE_PATH}/$(date --date "@${DATE}" '+%Y/%m')"
mkdir -p "${NOTE_PATH}" || return 1
local NOTE_PATH="${NOTE_PATH}/$(date --date "@${DATE}" '+%d').md"
else
mkdir -p "$(dirname "${NOTE_PATH}")" || return 2
fi
vim "${NOTE_PATH}" || return 3
}

View file

@ -1,12 +0,0 @@
#!/bin/bash
# pkc : read the content to copy to the clipboard from STDIN
alias pkc='piknik -copy'
# pkp : paste the clipboard content
alias pkp='piknik -paste'
# pkm : move the clipboard content
alias pkm='piknik -move'
# pkz : delete the clipboard content
alias pkz='piknik -copy < /dev/null'

158
home/.zshrc Normal file
View file

@ -0,0 +1,158 @@
export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:${PATH}"
# oh-my-zsh {
export ZSH="${HOME}/.oh-my-zsh"
ZSH_THEME="candy"
HYPHEN_INSENSITIVE="true"
export UPDATE_ZSH_DAYS=7
DISABLE_UPDATE_PROMPT="true"
HIST_STAMPS="mm/dd/yyyy"
plugins=(battery catimg docker fzf git go golang grunt helm kube-ps1 kubectl minikube node npm pip ssh-agent sudo tmux)
source $ZSH/oh-my-zsh.sh
# }
# zsh {
HISTFILE="${HOME}/.histfile"
HISTSIZE=1048576
SAVEHIST=1048576
setopt \
appendhistory \
autocd \
beep \
extendedglob \
nomatch \
notify \
HIST_IGNORE_DUPS \
INC_APPEND_HISTORY \
SHARE_HISTORY \
HIST_REDUCE_BLANKS
# }
# general {
export LANG='en_US.UTF-8'
export TERM='xterm-256color'
export EDITOR='vim'
# if nvim is installed, effectively replace vim
if command -v nvim &> /dev/null; then
export EDITOR='nvim'
alias vi='nvim'
alias vim='nvim'
alias vimdiff="nvim -d"
alias view="nvim -R"
fi
export VISUAL="${EDITOR}"
# use reflink cp if supported (yay CoW)
if cp --help | grep -q reflink; then
alias cp='cp -i --reflink=auto'
else
alias cp='cp -i'
fi
alias mv='mv -i'
alias dco='docker-compose'
alias mk='minikube'
alias k='kubectl'
alias kctx='kubectx'
alias kns='kubens'
REPOS="${HOME}/repos"
PHPCS_BIN="${REPOS}/phpcs/scripts"
if [ -d "${PHPCS_BIN}" ]; then
export PATH="${PHPCS_BIN}:${PATH}"
fi
CARGO_ENV="${HOME}/.cargo/env"
if [ -f "${CARGO_ENV}" ]; then
source "${CARGO_ENV}"
fi
if [ -x "${REPOS}/termpdf/termpdf" ]; then
alias termpdf="${REPOS}/termpdf/termpdf"
fi
# add awless autocompletion if available
if command -v awless &> /dev/null; then
source <(awless completion zsh)
fi
# add kubectl autocompletion if available
if command -v kubectl &> /dev/null; then
source <(kubectl completion zsh)
fi
# add helm autocompletion if available
if command -v helm &> /dev/null; then
source <(helm completion zsh)
fi
# add aws autocompletion if available
if command -v aws &> /dev/null; then
complete -C aws_completer aws
fi
if command -v fzf &> /dev/null; then
export FZF_DEFAULT_COMMAND='ag --skip-vcs-ignores --nocolor -g "" -l'
export FZF_CTRL_T_COMMAND="${FZF_DEFAULT_COMMAND}"
fi
NIX_SH="${HOME}/.nix-profile/etc/profile.d/nix.sh"
if [ -f "${NIX_SH}" ]; then
source "${NIX_SH}"
fi
export GOAPPS=(
'github.com/dgraph-io/badger/...'
'github.com/golang/protobuf/protoc-gen-go'
'github.com/google/huproxy/huproxyclient'
'github.com/jedisct1/piknik'
'github.com/junegunn/fzf'
'github.com/schachmat/wego'
'github.com/tomnomnom/gron'
'github.com/wallix/awless'
'google.golang.org/grpc'
)
case `uname` in
"Darwin")
pdf_join() {
join_py="/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"
echo -n "Name of output file: "
read output_file && "$join_py" -o $output_file $@ && open $output_file
}
if command -v gtar &> /dev/null; then
alias tar='gtar'
fi
export VISUAL='nvim'
#archey -c
;;
"Linux")
#screenfetch
alias open="xdg-open"
# swap escape and caps lock keys if gnome
if command -v dconf &> /dev/null; then
if ! dconf read /org/gnome/desktop/input-sources/xkb-options | grep -q 'caps:swapescape'; then
dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:swapescape']"
fi
fi
;;
esac
# }
# load any file that ends with .zsh or .sh
for SCRIPT in "${HOME}/.zshrc.d"/**/(.|?)*(.zsh|.sh); do
if ! [ -x "${SCRIPT}" ]; then
continue
fi
source "${SCRIPT}"
done
source "${HOME}/.homesick/repos/homeshick/homeshick.sh"
homeshick refresh 5 -q

13
home/.zshrc.d/00_go.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/bash
export GOROOT="${HOME}/.goroot"
export PATH="${GOROOT}/bin:${PATH}"
if command -v go &> /dev/null; then
GOPATH="$(go env GOPATH)"
if [ -n "${GOPATH}" ]; then
export GOPATH
export PATH="${GOPATH}/bin:${PATH}"
fi
else
>&2 echo '"go" is missing from the PATH, you should run "install.sh"'
fi

View file

@ -1,20 +1,22 @@
#!/bin/bash
# updates go binary installs that you care about.
# if the GOAPPS environment variable is set, it is expected to be
# an array
update_go_apps() {
local APPS=($@)
local APPS=("${@}")
if [ -z "${APPS}" ]; then
if [ -z "${APPS[0]}" ]; then
if [ -z "${GOAPPS}" ]; then
return
fi
APPS=(${GOAPPS[@]})
APPS=("${GOAPPS[@]}")
fi
local APP
for APP in "${APPS[@]}"; do
echo "Updating ${APP}"
go get -u "${APP}"
go get -u "${APP}" || return $?
done
}

View file

@ -0,0 +1,35 @@
#!/bin/bash
upgrade_system() {
if command -v apt &> /dev/null; then
sudo sh -c 'apt update && apt upgrade' || return $?
fi
if command -v dnf &> /dev/null; then
sudo dnf upgrade || return $?
fi
if command -v update_go_apps &> /dev/null; then
update_go_apps || return $?
fi
if command -v vim &> /dev/null; then
vim -c 'PlugUpgrade | q' || return $?
vim -c 'PlugUpdate | sleep 3 | qa' || return $?
fi
(
cd "${HOME}/.tmux/plugins/tpm" || exit 0
if [ -x ./clean_plugins ]; then
./clean_plugins || exit $?
fi
if [ -x ./install_plugins ]; then
./install_plugins || exit $?
fi
if [ -x ./update_plugins ]; then
./update_plugins all || exit $?
fi
) || return $?
}

37
home/.zshrc.d/fup.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
# fup uploads a given file to file.io
fup() {
local -r FILE_PATH="${1}"
local -r EXPIRATION="${2}"
if ! [ -f "${FILE_PATH}" ]; then
echo 'provide a valid file path'
return 1
fi
local URL='https://file.io/'
if [ -n "${EXPIRATION}" ]; then
URL="${URL}?expires=${EXPIRATION}"
fi
local JSON_RETURN
if ! JSON_RETURN="$(curl -SsfLF "file=@${FILE_PATH}" "${URL}")"; then
echo 'Curl failed'
return 1
fi
if echo "${JSON_RETURN}" | grep -q '"success":false'; then
echo "${JSON_RETURN}"
return 2
fi
echo "https://file.io/$(echo "${JSON_RETURN}" | sed 's/.*key":"//' | sed 's/".*//')"
if echo "${JSON_RETURN}" | grep -q '"expiry":'; then
echo "Expires in $(echo "${JSON_RETURN}" | sed 's/.*expiry":"//' | sed 's/".*//')"
else
echo 'Expires in 14 days'
fi
return 0
}

View file

@ -1,6 +1,7 @@
#!/bin/bash
# convert integer to IP
int2ip () {
local ip dec=$@
local ip dec=("$@")
for e in {3..0}
do
((octet = dec / (256 ** e) ))
@ -14,7 +15,8 @@ int2ip () {
# convert IP to integer
ip2int () {
local a b c d ip=$@
IFS=. read -r a b c d <<< "$ip"
local a b c d ip
ip=("$@")
IFS=. read -r a b c d <<< "${ip[*]}"
printf '%d\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))"
}

View file

@ -11,7 +11,7 @@ sshtmux() {
fi
tmux new-window "ssh"
for i in ${@}; do
for i in "${@}"; do
tmux split-window -h "ssh -o StrictHostKeyChecking=no $i"
tmux select-layout tiled > /dev/null
sleep .1s

17
home/.zshrc.d/weather.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
weather() {
if ! command -v wego &> /dev/null; then
return 1
fi
local -r LOCK_DATE="/tmp/wego-$(date '+%F-%H')"
if [ -e "${LOCK_DATE}" ]; then
return 0
fi
touch "${LOCK_DATE}"
wego
}
weather

103
install.sh Executable file
View file

@ -0,0 +1,103 @@
#!/bin/bash
check_required_cmds() {
local -r REQUIRED_CMDS=(
'curl'
'git'
'sha256sum'
'tar'
'tmux'
'vim'
'zsh'
)
local RETURN=0
local REQUIRED_CMD
for REQUIRED_CMD in ${REQUIRED_CMDS[*]}; do
if ! command -v "${REQUIRED_CMD}" &> /dev/null; then
>&2 echo "Missing '${REQUIRED_CMD}' from PATH"
RETURN=1
fi
done
return "${RETURN}"
}
install_homeshick() {
local -r HOMESHICK_DIR="${HOME}/.homesick/repos/homeshick"
if [ -d "${HOMESHICK_DIR}" ]; then
echo 'homeshick is already installed'
return
fi
git clone https://github.com/andsens/homeshick.git "${HOMESHICK_DIR}"
}
install_ohmyzsh() {
if [ -d "${HOME}/.oh-my-zsh" ]; then
echo 'oh-my-zsh is already installed'
return
fi
/bin/bash -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
}
install_tpm() {
local -r TPM="${HOME}/.tmux/plugins/tpm"
if [ -d "${TPM}" ]; then
echo 'tpm is already installed'
return
fi
git clone https://github.com/tmux-plugins/tpm "${TPM}"
}
install_go() {
local -r GO_VERSION='1.13.5'
local -r GO_SHA256='512103d7ad296467814a6e3f635631bd35574cab3369a97a323c9a585ccaa569'
source "./home/.zshrc.d/00_go.sh"
if command -v go &> /dev/null; then
echo 'go is already installed'
return
fi
echo 'Installing Go 1.13.5, ensure that this is the version you want'
local -r GO_TAR_FILE="$(mktemp)"
if ! [ -f "${GO_TAR_FILE}" ]; then
>&2 echo 'failed to create a file for the go tar'
return 1
fi
if ! curl -L "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" |
tee "${GO_TAR_FILE}" |
sha256sum |
grep -Fq "${GO_SHA256}"; then
>&2 echo 'failed to download go tar'
return 2
fi
mkdir -p "${GOROOT}" || return $?
(
cd "${GOROOT}" || exit $?
tar -xzf "${GO_TAR_FILE}" || exit $?
mv go/* ./ || exit $?
rmdir go || exit $?
) || return $?
rm "${GO_TAR_FILE}" || true
}
check_required_cmds || exit $?
echo 'installing homeshick'
install_homeshick
echo 'installing go'
install_go || exit $?
echo 'installing tpm'
install_tpm || exit $?
echo 'installing oh-my-zsh'
install_ohmyzsh || exit $?
echo 'now in zsh, run "upgrade_system"'