Skip to content

Instantly share code, notes, and snippets.

@ambakshi
Last active January 24, 2024 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ambakshi/51c994271a216016edef to your computer and use it in GitHub Desktop.
Save ambakshi/51c994271a216016edef to your computer and use it in GitHub Desktop.
Bootstrap vim and tmux
#!/bin/bash
# shellcheck disable=SC1073,SC1007,SC1072,SC1090,SC1091,SC2015
if [[ $UID -ne 0 ]]; then
if ! type -t __git_ps1 >/dev/null 2>&1 && test -e /usr/share/git-core/contrib/completion/git-prompt.sh; then
. /usr/share/git-core/contrib/completion/git-prompt.sh
fi
if type -t __git_ps1 >/dev/null 2>&1; then
PS1='[\[\033[32m\]\u@\h\[\033[00m\] \[\033[36m\]\W\[\033[31m\]$(__git_ps1)\[\033[00m\]] \$ '
else
PS1='[\[\033[32m\]\u@\h\[\033[00m\] \[\033[36m\]\W\[\033[31m\]\[\033[00m\]] \$ '
fi
else
PS1='\[\e[31m\]\h:\w#\[\e[m\] '
fi
alias c=clear
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias d=docker
alias dc=docker-compose
alias drm='docker ps -aq | xargs -r docker rm'
alias drmi='docker images --filter=dangling=true -q | xargs -r docker rmi'
alias di='docker images'
alias dps='docker ps'
alias egrep='egrep --color=auto'
alias ff='find . -type f | grep -E'
alias gf='git ls-files | egrep'
alias gs='git status --short'
alias gst='gs -uno'
alias gg='git grep'
alias gd='git diff'
alias glg='git lg'
alias gdh='git diff HEAD~'
alias gds='git diff HEAD~ --stat'
alias gdc='git diff --cached'
alias gru='git remote update'
alias g='git'
alias ltr='ls -ltr'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -I'
glr () {
git ls-tree -r HEAD "$@"
}
# For creating a new session
#shellcheck disable=SC1002,SC2086
tnew_session(){
# To avoid 'unset $TMUX to force' error
TMUX= tmux new-session -d -s $1
tmux switch-client -t $1
}
# Aliases
alias tnews='tnew_session'
alias tls='tmux list-session'
alias tlw='tmux list-window'
alias tsw='tmux switch -t '
alias tlc='tmux list-command'
alias tat='tmux attach -t'
alias trs='tmux rename-session -t'
alias tks='tmux kill-session -t'
export HISTSIZE=100000000
export HISTFILESIZE=200000000
export HISTCONTROL=ignoreboth:erasedups
export HISTFILE=$HOME/.bash_forever_history
export HISTTIMEFORMAT='%FT%T%z%t'
shopt -s histappend
shopt -s checkwinsize
set -o braceexpand
if ! echo "$PATH" | grep -q "$HOME/bin"; then
PATH="$PATH:$HOME/bin"
export PATH
fi
if command -v go &>/dev/null; then
PATH="$PATH:${GOPATH:-$HOME/go}/bin"
export PATH
fi
set -o vi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash || true
#!/usr/bin/env bash
#
# install: curl -fsSL https://gist.githubusercontent.com/ambakshi/51c994271a216016edef/raw/bootstrap.sh | bash -e
# fork: https://gist.github.com/ambakshi/51c994271a216016edef
# short url: curl -fsSL http://bit.ly/devbootstrap | bash -e
#
# ChangeLog:
# 01/24/2024 - Add asdf.sh
# 07/20/2022 - Fix hashitool downloads
# 09/26/2020 - Modularize script
# 12/21/2016 - Add Arch support
# 05/19/2017 - Add .gdbinit
# 05/28/2018 - Add amazon linux support
# 01/09/2021 - Moved config files to $XDG_CONFIG_HOME
# 01/05/2023 - Add EL9 support
# Amit Bakshi
#
# shellcheck disable=SC2086,SC2046,SC1091,SC21153,SC2015,SC2207,2155
_osid() {
unset ELVERSION UBVERSION VERSTRING VERSION_ID ID PRETTY_NAME VERSION
if [[ $OSTYPE =~ darwin ]]; then
VERSTRING="$OSTYPE"
elif [[ $OSTYPE =~ freebsd ]]; then
VERSTRING="$OSTYPE"
elif [ -f /etc/os-release ]; then
. /etc/os-release
if [ -n "$PLATFORM_ID" ]; then
:
fi
case "$ID" in
antergos)
VERSTRING="arch"
;;
rocky | almalinux | rhel | ol | centos)
ELVERSION="$(echo $VERSION_ID | cut -d'.' -f1)"
VERSTRING="el${ELVERSION}"
;;
ubuntu)
UBVERSION="$(echo $VERSION_ID | cut -d'.' -f1)"
VERSTRING="ub${UBVERSION}"
;;
amzn)
if [[ $CPE_NAME =~ ^cpe:/o:amazon:linux:20 ]]; then
ELVERSION=6
VERSTRING=amzn1
else
ELVERSION=7
VERSTRING=amzn2
fi
PYTHON_DEPS="make gcc patch zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel libuuid-devel gdbm-libs libnsl2"
;;
*)
# shellcheck disable=SC2153
echo >&2 "Unknown OS version: $PRETTY_NAME ($VERSION)"
;;
esac
fi
if [ -z "$VERSTRING" ] && [ -e /etc/system-release ]; then
RELEASE="$(rpm -q $(rpm -qf /etc/system-release) --queryformat '%{VERSION}')"
case "$RELEASE" in
6Server) VERSTRING="rhel6" ;;
7Server) VERSTRING="rhel7" ;;
8Server) VERSTRING="rhel8" ;;
9Server) VERSTRING="rhel9" ;;
6) VERSTRING="el6" ;;
7) VERSTRING="el7" ;;
8) VERSTRING="el8" ;;
9) VERSTRING="el9" ;;
*)
echo >&2 "Unknown version of EL: $RELEASE"
echo >&2 "Please set VERSTRING to rhel6, el6, rhel7 or el7 manually before running this script"
exit 1
;;
esac
ELVERSION="${RELEASE:0:1}"
VERSTRING="${VERSTRING:-el${ELVERSION}}"
fi
if [ -z "$VERSTRING" ]; then
cat >&2 /etc/*-release
echo >&2 "Unknown OS version"
uname -a >&2
exit 1
fi
[ $# -eq 0 ] && set -- -f
for cmd in "$@"; do
case "$cmd" in
-f | --full) echo "$VERSTRING" ;;
-s | --split) echo "$VERSTRING" | sed -E -e 's/([a-z]+)([0-9\.]+)/\1 \2/g' ;;
-p | --package)
case "$VERSTRING" in
ub*) echo "deb" ;;
amzn* | el* | rhel*) echo "rpm" ;;
esac
;;
-*)
echo >&2 "Unknown option $cmd"
exit 1
;;
esac
done
}
have_pkg() {
local pkg=
if [[ $OSID_NAME =~ ^ub ]]; then
for pkg in "$@"; do
dpkg -l $pkg &>/dev/null || return 1
done
return 0
elif [[ $OSID_NAME =~ el(6|7|8|9)$ ]] || [[ $OSID_NAME =~ ^amzn ]]; then
for pkg in "$@"; do
rpm -q $pkg &>/dev/null || return 1
done
return 0
fi
return 1
}
have_cmd () {
local p
for p in "$@"; do
command -v "$p" >/dev/null || return 1
done
return 0
}
info() {
echo >&2 "info: $1"
}
die() {
echo >&2 "ERROR: $1"
exit 1
}
install_pkg() {
if [ "${ELVERSION:-0}" -gt 7 ]; then
$SUDO dnf install -q -y "$@"
elif [[ $OSID_NAME =~ ^ub ]]; then
$SUDO apt-get update -yqq
$SUDO DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends "$@"
elif [[ $OSID_NAME =~ ^el ]] || [[ $OSID_NAME =~ ^amzn ]]; then
$SUDO yum install -y -q "$@"
elif [[ $OSID_NAME =~ ^freebsd ]]; then
$SUDO pkg install -y "$@"
elif [[ $OSID_NAME =~ ^darwin ]]; then
local pkg=
for pkg in "$@"; do
brew install $pkg
done
elif [[ $OSID_NAME =~ arch ]]; then
$SUDO pacman -S --noconfirm "$@"
else
echo >&2 "Don't know how to install $* on $OSID_NAME"
return 1
fi
}
install_pkgs() {
local ii
local pkgs=()
for ii in "$@"; do
have_pkg "$ii" || pkgs+=("$ii")
done
if [ ${#pkgs[*]} -gt 0 ]; then
install_pkg "${pkgs[@]}"
fi
}
install_setup() {
local pkgs=()
if [[ $OSID_NAME =~ ^darwin ]]; then
command -v brew >/dev/null || $SUDO -H ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" || exit 1
brew update
elif [[ $OSID_NAME =~ ^freebsd ]]; then
pkg install -y git tmux curl
elif [[ $OSID_NAME =~ ^ub ]]; then
if ! have_cmd git curl unzip; then
echo >&2 "installing setup requirements ..."
install_pkgs curl software-properties-common git curl unzip
fi
elif [[ $OSID_NAME =~ ^el ]] || [[ $OSID_NAME =~ ^amzn ]]; then
install_pkgs sudo curl git tar gzip
[ $OSID_NAME = amzn2 ] && $SUDO amazon-linux-extras install -y epel || install_pkg epel-release unzip curl git
elif [[ $OSID_NAME =~ rhel ]]; then
$SUDO dnf -y install dnf-plugins-core https://dl.fedoraproject.org/pub/epel/epel-release-latest-${ELVERSION}.noarch.rpm curl git unzip
elif [[ $OSID_NAME =~ arch ]]; then
$SUDO pacman -S --noconfirm git curl
elif test -e /etc/system-release; then
$SUDO dnf install -y dnf-plugins-core epel-release curl git tar gzip unzip
fi
}
setup_nvim() {
$SUDO update-alternatives --install /usr/bin/vi vi /usr/bin/nvim 60
$SUDO update-alternatives --skip-auto --config vi
$SUDO update-alternatives --install /usr/bin/vim vim /usr/bin/nvim 60
$SUDO update-alternatives --skip-auto --config vim
$SUDO update-alternatives --install /usr/bin/editor editor /usr/bin/nvim 60
$SUDO update-alternatives --skip-auto --config editor
$SUDO -H pip install -U neovim || true
$SUDO -H pip2 install -U neovim || true
$SUDO -H pip3 install -U neovim || true
}
install_vim() {
if have_cmd vim; then
return 0
fi
echo >&2 "installing vim ..."
if [ -n "$ASDF_DIR" ]; then
asdf plugin-add neovim
asdf install neovim latest
asdf global neovim latest
elif [[ $OSID_NAME =~ ^darwin ]]; then
install_pkg neovim/neovim/neovim
elif [[ $OSID_NAME =~ ^freebsd ]]; then
pkg install -y neovim
elif [[ $OSID_NAME =~ ^ub ]]; then
if [[ $OSID_VERSION -lt 18 ]]; then
$SUDO add-apt-repository -y ppa:neovim-ppa/stable
$SUDO apt-get update -qq
$SUDO DEBIAN_FRONTEND=noninteractive apt-get install -qqy neovim python-dev python-pip python3-dev python3-pip --no-install-recommends
setup_nvim
else
$SUDO apt-get update -qq
$SUDO DEBIAN_FRONTEND=noninteractive apt-get install -qqy vim-nox python3-dev python3-pip --no-install-recommends
$SUDO update-alternatives --install /usr/bin/editor editor /usr/bin/vim 60
$SUDO update-alternatives --skip-auto --config editor
fi
elif [[ $OSID_NAME =~ arch ]]; then
pacman -S --noconfirm tmux neovim
elif [[ $OSID_NAME =~ ^el ]] && [[ $OSID_VERSION -ge 7 ]]; then
$SUDO dnf install -y neovim universal-ctags shellcheck shfmt ripgrep patchelf restic || true
setup_nvim
elif [[ $OSID =~ amzn2 ]]; then
$SUDO amazon-linux-extras install -y vim ruby2.6
else
echo >&2 "Don't know how to install neovim on ${OSID_NAME}${OSID_VERSION}"
return 1
fi
}
install_golang_tools() {
export GOPATH=${GOPATH:-$HOME/go}
local tmp=$(mktemp -d -t gitXXXXXX)
mkdir -p $HOME/bin/
(
set -e
git clone --branch v2.8.2 https://github.com/hashicorp/hcl $tmp/hcl
cd $tmp/hcl/cmd/hclfmt
go build -o ~/bin/hclfmt
)
rm -rf $tmp
go get github.com/direnv/direnv
for pkg in "$GOPATH"/bin/*; do
if ((IS_ROOT)); then
$SUDO ln -sfn ${pkg} /usr/local/bin/
fi
ln -sfn ${pkg} $HOME/bin/
done
}
install_golang() {
BASEURL=https://golang.org
if [ -z "$1" ]; then
echo >&2 "${FUNC_NAME[0]}: Must specify destination dir"
return 1
fi
if ! GOURL=$(curl -fsSL $BASEURL/dl | grep -Eow 'dl/go1\.([0-9\.]+)linux-amd64.tar.gz' | head -1); then
return 1
fi
local version
version="1.$(echo $GOURL | grep -Eow '([0-9\.]+)')"
if ! test -x "$1"/go${version}/bin/go; then
mkdir -p "$1"/go${version} || return 1
curl -fL "${BASEURL}/${GOURL}" | $SUDO tar zxf - -C "$1"/go${version} --strip-components=1
fi
$SUDO ln -sfn go${version} "$1"/go
test -e "$1"/bin || $SUDO mkdir -p "$1"/bin
for cmd in go gofmt; do
$SUDO ln -sfn ../go/bin/${cmd} "$1"/bin/${cmd}
done
}
install_extras() {
if test -e /etc/system-release; then
$SUDO yum localinstall -y https://storage.googleapis.com/repo.xcalar.net/xcalar-release-${OSID}.rpm || true
$SUDO yum -y --enablerepo='xcalar*' install tmux universal-ctags shellcheck shfmt ripgrep patchelf restic direnv shellcheck || true
fi
}
export BACKUP_DT=${BACKUP_DT:-$(date +%Y%m%d-%H%M)}
backup_name() {
echo "$1"-"$BACKUP_DT"
}
restore() {
info "Restoring $1 ..."
mv -v "$(backup_name "$1")" "$1"
}
backup() {
local ii
for ii in "$@"; do
test -e "$ii" || continue
if test -L "$ii"; then
rm -v "$ii"
else
mv -v "$ii" "$(backup_name "$ii")" || die "Failed to backup $*"
fi
done
}
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
install_python() {
local ver="${1:-"latest:3.11"}"
if [ -n "$ASDF_DIR" ]; then
if [[ $OSID_NAME =~ ^el ]]; then
PYTHON_DEPS="make gcc patch zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel libuuid-devel gdbm-libs libnsl2"
elif [[ $OSID_NAME =~ ^ub ]]; then
PYTHON_DEPS="build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev"
fi
if ! ((NOROOT)); then
install_pkgs $PYTHON_DEPS
fi
export PYTHON_CONFIGURE_OPTS='--enable-optimizations --with-lto' \
PYTHON_CFLAGS='-march=native -mtune=native' \
EXTRA_CFLAGS='-Wno-unused-function' PROFILE_TASK='-m test.regrtest --pgo -j0' \
MAKE_OPTS="-j$(( $(nproc) * 2 ))"
asdf plugin-add python
asdf install python $ver
asdf global python $ver
fi
}
install_asdf() {
ASDF_DEFAULT_REMOTE="${ASDF_DEFAULT_REMOTE:-https://github.com/asdf-vm/asdf.git}"
ASDF_DEFAULT_TAG="${ASDF_DEFAULT_TAG:-v0.14.0}"
ASDF_DEFAULT_DIR="${HOME?HOME must be set}"/.asdf
local asdfDir="${ASDF_DIR:-$ASDF_DEFAULT_DIR}"
if ! test -e "$asdfDir"/asdf.sh; then
git -c advice.detachedHead=false clone "$ASDF_DEFAULT_REMOTE" "$asdfDir" --branch "$ASDF_DEFAULT_TAG"
fi
unset ASDF_DIR
. "$asdfDir"/asdf.sh
asdf plugin-add direnv
asdf install direnv latest
asdf global direnv latest
local begin_marker="### begin install asdf ###" end_marker="### end install asdf ###"
local short="${asdfDir/$HOME/\"\$HOME\"}" shell
for shell in bash zsh; do
hash "$shell" 2>/dev/null || continue
local profile="$HOME/.${shell}rc" compl="$asdfDir/completions/asdf.${shell}"
touch "$profile"
sed -r -i.bak "/^${begin_marker}/,/^${end_marker}/d" "$profile"
printf '\n%s\n' "$begin_marker" >> "$profile"
printf '. %s/asdf.sh\n' "$short" >> "$profile"
test -f "$compl" && printf '. %s\n' "${compl/$HOME/\"\$HOME\"}" >> "$profile" || true
asdf direnv setup --shell "$shell" --version latest
printf '%s\n' "$end_marker" >> "$profile"
done
echo >&2 "Please restart your shell to enable asdf: exec \$SHELL"
}
declare -r VIM="$XDG_CONFIG_HOME"/vim
declare -r VIMRC="$VIM"/vimrc
VIMURL="https://gist.githubusercontent.com/ambakshi/51c994271a216016edef/raw/vimrc"
install_vim_config() {
# shellcheck disable=SC2235
if test -L "$HOME"/.vim && test -d "$HOME/.vim"; then
if [ "$(readlink -f "$HOME"/.vim)" = "$VIM" ]; then
info "Vim home already exists"
fi
elif test -d "$HOME"/.vim && ! test -L "$HOME/.vim"; then
if ! test -d "$VIM"; then
mkdir -p "$(dirname $VIM)" && mv "$HOME/.vim" "$VIM" || die "Failed to move $HOME/.vim"
fi
fi
backup "$HOME/.vim" || die "Failed to backup $HOME/.vim"
if mkdir -p "$VIM"/{backup,plugged,undo,autoload,tmp/bundle}; then
backup "$HOME/.vim"
ln -sfn "$VIM" "$HOME/.vim"
fi
update_vim_config
}
update_vim_config() {
backup "$VIMRC"
if ! curl -fsSL "$VIMURL" -o "$VIMRC"; then
restore "$VIMRC"
fi
backup "$XDG_CONFIG_HOME/nvim"
ln -sfn "$(basename "$VIM")" "$XDG_CONFIG_HOME/nvim"
ln -sfn vimrc "$(dirname "$VIMRC")"/init.vim
if ! command -v ctags &>/dev/null; then
sed -i.bak "s#^Plug 'vim-scripts/taglist.vim'#\" Plug 'vim-scripts/taglist.vim'#g" $VIMRC
info "No ctags found. Commenting out taglist.vim plugin from ~/.vimrc"
fi
curl -fsSL --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -o $VIM/autoload/plug.vim
if ! test -x "$HOME"/bin/diff-highlight; then
curl -fsSL --create-dirs https://raw.githubusercontent.com/git/git/fd99e2bda0ca6a361ef03c04d6d7fdc7a9c40b78/contrib/diff-highlight/diff-highlight -o "$HOME"/bin/diff-highlight \
&& chmod +x "$HOME"/bin/diff-highlight
fi
## Get rid of YouCompleteMe plugin if you can't build it.
#if ! which cmake &>/dev/null; then
# sed -i.bak "s#^Plugin 'Valloric/YouCompleteMe'#\" Plugin 'Valloric/YouCompleteMe'#g" ~/.vimrc
# echo >&2 "No cmake found. Commenting out YouCompleteMe plugin form ~/.vimrc"
#fi
if [ -r /dev/tty ]; then
bash -c '</dev/tty vim "$@"' vim -T dumb '+PlugInstall' '+PlugUpgrade' '+qall!' || true
elif ! [[ $OSTYPE =~ ^freebsd ]]; then
if command -v nvim &>/dev/null; then
nvim --headless -c ':PlugUpgrade' -c ':PlugUpdate' -c ':qall' || true
elif command -v vim &>/dev/null; then
vim -T dumb -c ':PlugUpgrade' -c ':PlugUpdate' -c ':qall' || true
fi
fi
#fi
#(cd ~/.vim/bundle/vim-airline/autoload/airline/themes && wget https://raw.githubusercontent.com/vim-airline/vim-airline-themes/master/autoload/airline/themes/powerlineish.vim)
##[ -e ~/.vim/bundle/YouCompleteMe ] && cd ~/.vim/bundle/YouCompleteMe && git submodule update --init && ./install.sh || true
}
install_arkade() {
$SUDO curl -fsSL https://github.com/alexellis/arkade/releases/download/0.6.23/arkade --o /usr/local/bin/arkade
$SUDO chmod +x /usr/local/bin/arkade
}
install_config() {
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
mkdir -p $XDG_CONFIG_HOME/git
GNAME="$(git config user.name)" || :
GEMAIL="$(git config user.email)" || :
GITCONF=$XDG_CONFIG_HOME/git/config
if test -e ~/.gitconfig || test -e $GITCONF; then
backup ~/.gitconfig
fi
curl -fsSL https://gist.github.com/ambakshi/d111202b21041db55a80/raw -o ${GITCONF}
[ -n "$GNAME" ] && git config --global user.name "$GNAME" || :
[ -n "$GEMAIL" ] && git config --global user.email "$GEMAIL" || :
test -e ~/.tmux.conf || curl -fsSL https://gist.githubusercontent.com/ambakshi/51c994271a216016edef/raw/tmuxconf -o ~/.tmux.conf
test -e ~/.inputrc || curl -fsSL https://gist.githubusercontent.com/ambakshi/51c994271a216016edef/raw/inputrc -o ~/.inputrc
test -e ~/.bash_aliases || curl -fsSL https://gist.githubusercontent.com/ambakshi/51c994271a216016edef/raw/bash_aliases -o ~/.bash_aliases
test -e ~/.gdbinit || curl -fsSL https://gist.githubusercontent.com/CocoaBeans/1879270/raw/c6972d5c32e38e9f35a3968c629b51973bd9d016/gdbinit -o ~/.gdbinit
}
usage() {
echo "usage: $0 [--[no-]config] [--[no-]vim] [--[no-]vim-config] [--[no-]golang ] [--[no-]extras] [--[no-]golang-tools] [--hashitool[=x.y.z]]"
echo
}
hashilatest () {
local version;
if version="$(curl -fsSL https://releases.hashicorp.com/$1/ | grep -Ev -- '-(alpha|beta|rc)' | grep -Eow "${1}_[0-9\.]+" | grep -Eo '([0-9\.]+)' | sort -rV | head -1)"; then
echo "$version"
return 0;
fi;
return 1
}
hashiurl ()
{
local tool="$1" version
shift
if [ $# -gt 0 ]; then
version="$1"
shift
fi
if [ -z "$version" ] || [ "$version" = latest ]; then
if ! version="$(hashilatest $tool)"; then
return 1;
fi;
fi;
local target
target="$(uname -s)";
target="${target,,}";
ARCH="amd64";
case "$(uname -m)" in
x86_64)
ARCH=amd64
;;
arm64)
ARCH=arm64
;;
*)
echo "Unknown architecture: $(uname -m)" 1>&2;
return 1
;;
esac;
echo "https://releases.hashicorp.com/${tool}/${version}/${tool}_${version}_${target}_${ARCH}.zip"
}
download_hashitool ()
{
local tool="$1";
local version="$2";
echo >&2 " -- download_hashitool $*"
if test -e "$tool"; then
echo "$tool already exists" 1>&2;
return 1;
fi;
local target
target="$(uname -s | tr '[:upper:]' '[:lower:]')";
local arch="amd64";
case "$(uname -m)" in
x86_64)
arch=amd64
;;
*)
echo "Unknown architecture: $(uname -m)" 1>&2;
return 1
;;
esac
local url
if ! url="$(hashiurl $tool $version)"; then
return 1
fi
if ! curl -fsSL "$url" -o ${tool}-$$.zip > /dev/null 2>&1; then
return 1
fi
local pzip="unzip"
if have_cmd unzip; then
pzip="unzip -o -q"
elif have_cmd 7z; then
pzip="7z x"
else
echo >&2 "unzip not found, leaving ${tool}.zip"
mv ${tool}-$$.zip ${tool}.zip
return
fi
$pzip ${tool}-$$.zip 1>&2 && rm -vf ${tool}-$$.zip || return 1
if ((IS_ROOT)); then
$SUDO mv "$tool" /usr/local/bin/
else
local d
for d in ~/.local/bin ~/bin; do
if test -d "$d"; then
mv -v "$tool" "$d"/ && break
fi
done
fi
}
main() {
local tool cmd
: "${XDG_CONFIG_HOME:="$HOME"/.config}"
export XDG_CONFIG_HOME
export NOW="$(date +%Y%m%d-%H%M)"
_VER=($(_osid -s))
OSID=$(_osid)
OSID_NAME="${_VER[0]}"
OSID_VERSION="${_VER[1]}"
SUDO=''
NOROOT=0
GOINSTALL=/usr/local
INSTALL_CONFIG=${INSTALL_CONFG:-0}
CONFIG_ONLY=${CONFIG_ONLY:-0}
INSTALL_VIM=${INSTALL_VIM:-0}
INSTALL_VIM_CONFIG=${INSTALL_VIM_CONFIG:-0}
INSTALL_GOLANG=${INSTALL_GOLANG:-0}
INSTALL_GOLANG_TOOLS=${INSTALL_GOLANG_TOOLS:-0}
INSTALL_NEOVIM=${INSTALL_NEOVIM:-0}
INSTALL_EXTRAS=${INSTALL_EXTRAS:-0}
INSTALL_ASDF=${INSTALL_ASDF:-1}
INSTALL_PYTHON=${INSTALL_PYTHON:-0}
IS_ROOT=0
INSTALLS=()
if test $(id -u) -ne 0; then
IS_ROOT=1
NOROOT=0
GOINSTALL="$HOME/.local"
command -v sudo >/dev/null && SUDO='sudo -H'
fi
while [ $# -gt 0 ]; do
cmd="$1"
shift
case "$cmd" in
-h|--help) usage; exit 0 ;;
--config) INSTALL_CONFIG=1;;
--no-config) INSTALL_CONFIG=0 ;;
--no-vim) INSTALL_VIM=0 ;;
--config-only) INSTALL_CONFIG=1; CONFIG_ONLY=1;;
--hashitool)
tool="${1%%=*}"
version="${1#${tool}=}"
if [ "$tool" = "$version" ]; then
download_hashitool "$tool" "latest"
else
download_hashitool "$tool" "$version"
fi
if ((IS_ROOT)); then
$SUDO mv "$tool" /usr/local/bin/
else
for d in ~/.local/bin ~/bin; do
if test -d "$d"; then
mv "$tool" "$d"/ && break
fi
done
fi
shift
;;
--vault|--nomad|--consul|--terraform|--packer)
tool="${cmd#--}"
if [[ "$1" =~ [0-9\.]+ ]] || [ "$1" = "latest" ]; then
download_hashitool "$tool" "$1"
shift
else
download_hashitool "$tool"
fi
;;
--vault=*|--nomad=*|--consul=*|--terraform=*|--packer=*)
tool="${cmd#--}"
version="${tool#*=}"
tool="${tool%=$version}"
download_hashitool "$tool" "$version"
;;
--noroot|--no-root) SUDO=''; NOROOT=1;;
--vim) INSTALL_VIM=1 ; INSTALLS+=(vim);;
--vim-config) INSTALL_VIM_CONFIG=1 ;;
--no-vim-config) INSTALL_VIM_CONFIG=0 ;;
--extras) INSTALL_EXTRAS=1 ; INSTALLS+=(extras);;
--no-asdf) INSTALL_ASDF=0;;
--python) INSTALL_PYTHON=1; INSTALLS+=(python);;
--no-extras) INSTALL_EXTRAS=0 ;;
--no-golang-tools) INSTALL_GOLANG_TOOLS=0 ;;
--golang-tools) INSTALL_GOLANG_TOOLS=1 ;;
--no-golang) INSTALL_GOLANG=0;;
--golang|--install-go*) INSTALL_GOLANG=1;;
*)
echo >&2 "Unknown command: $cmd"
usage >&2
exit 1
;;
esac
done
if ! ((CONFIG_ONLY)); then
if ((INSTALL_ASDF)); then
install_asdf
fi
if ! ((NOROOT)); then
# setup some basics (curl, epel, etc)
install_setup
# neovim
if ((INSTALL_VIM)); then
install_vim
fi
if ((INSTALL_EXTRAS)); then
install_extras
fi
fi
# golang
if ((INSTALL_PYTHON)); then
install_python "$PYTHON_VERSION"
fi
if ((INSTALL_GOLANG)); then
install_golang "$GOINSTALL"
fi
if ((INSTALL_GOLANG_TOOLS)); then
install_golang_tools
fi
fi
if ((INSTALL_VIM_CONFIG)); then
install_vim_config
fi
if ((INSTALL_CONFIG)); then
install_config
fi
# shellcheck disable=SC2016
echo >&2 'Logout and back in or source ~/.bashrc, or run exec -l $SHELL'
}
main "$@"
$include /etc/inputrc
set editing-mode vi
set keymap vi-insert
"\C-l": clear-screen
set keymap vi
#set completion-ignore-case on
#set show-all-if-ambiguous on
#set page-completions off
set match-hidden-files off
set expand-tilde off
set completion-query-items 200
set mark-symlinked-directories on
# Bash4 only? See https://github.com/mathiasbynens/dotfiles/blob/master/.inputrc
set skip-completed-text on
"\e[B": history-search-forward
"\e[A": history-search-backward
#set print-completion-horizontally on
set convert-meta on
set input-meta off
set output-meta off
set bell-style none
#set keymap vi-insert
$if editing-mode=vi
"\C-l": clear-screen
#"\C-p": dynamic-complete-history
"\C-p": history-search-backward
"\C-n": menu-complete
$endif
#tab: complete
#set completion-ignore-case on
#set blink-matching-paren on
#"\e[1~": beginning-of-line
#"\e[4~": end-of-line
#!/usr/bin/env bash
# shellcheck disable=SC2016
set -e
install_asdf_simple() {
ASDF_DEFAULT_REMOTE="${ASDF_DEFAULT_REMOTE:-https://github.com/asdf-vm/asdf.git}"
ASDF_DEFAULT_TAG="${ASDF_DEFAULT_TAG:-v0.14.0}"
ASDF_DEFAULT_DIR="${HOME?HOME must be set}"/.asdf
local asdfDir="${ASDF_DIR:-$ASDF_DEFAULT_DIR}"
if ! test -e "$asdfDir"/asdf.sh; then
git -c advice.detachedHead=false clone "$ASDF_DEFAULT_REMOTE" "$asdfDir" --branch "$ASDF_DEFAULT_TAG"
fi
unset ASDF_DIR
. "$asdfDir"/asdf.sh
asdf plugin-add direnv
asdf install direnv latest
asdf global direnv latest
local begin_marker="### begin install asdf ###" end_marker="### end install asdf ###"
local short="${asdfDir/$HOME/\"\$HOME\"}" shell
for shell in bash zsh; do
hash "$shell" 2>/dev/null || continue
local profile="$HOME/.${shell}rc" compl="$asdfDir/completions/asdf.${shell}"
touch "$profile"
sed -r -i.bak "/^${begin_marker}/,/^${end_marker}/d" "$profile"
printf '\n%s\n' "$begin_marker" >> "$profile"
printf '. %s/asdf.sh\n' "$short" >> "$profile"
test -f "$compl" && printf '. %s\n' "${compl/$HOME/\"\$HOME\"}" >> "$profile" || true
asdf direnv setup --shell "$shell" --version latest
printf '%s\n' "$end_marker" >> "$profile"
done
echo >&2 "Please restart your shell to enable asdf: exec \$SHELL"
}
install_asdf_simple
#!/bin/bash
#
# Scraped the golang site for the latest build and installs it
# into /usr/local/go$VERSION with symlinks in /usr/local/bin
#
install_golang() {
BASEURL=https://golang.org
if [ -z "$1" ]; then
echo >&2 "${FUNC_NAME[0]}: Must specify prefix, like /usr/local"
return 1
fi
local SUDO
if ! test -w "$1" && [ $(id -u) != 0 ]; then
SUDO=sudo
fi
if ! GOURL=$(curl -fsSL $BASEURL/dl | grep -Eow 'dl/go1\.([0-9\.]+)linux-amd64.tar.gz' | head -1) ; then
return 1
fi
local version="1.$(echo $GOURL | grep -Eow '([0-9\.]+)')"
if ! test -x "$1"/go${version}/bin/go; then
$SUDO mkdir -p "$1"/go${version} || return 1
curl -fL "${BASEURL}/${GOURL}" | $SUDO tar zxf - -C "$1"/go${version} --strip-components=1
fi
$SUDO ln -sfT go${version} "$1"/go
test -e "$1"/bin || $SUDO mkdir -p "$1"/bin
for cmd in go gofmt; do
$SUDO ln -sfT ../go/bin/${cmd} "$1"/bin/${cmd}
done
}
if [ "$(basename -- "$0")" = "$(basename -- "${BASH_SOURCE[0]}")" ]; then
install_golang "/usr/local"
fi
#!/bin/bash
set -e
install_neovim() {
install_url="https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz"
if [ $(id -u) -eq 0 ]; then
destdir=/usr
else
destdir="$HOME/.local"
mkdir -p $HOME/.local
fi
curl -fL "$install_url" | tar zxf - -C $destdir --strip-components=1
}
install_suexec() {
curl -fsSL https://github.com/ncopa/su-exec/raw/master/su-exec.c | gcc -x c -o /usr/bin/su-exec -Os -
}
setup_user() {
if [ -n "$SUDO_USER" ]; then
HOME=$(eval echo ~$SUDO_USER)
SUIDGID="${SUDO_UID}:${SUDO_GID}"
fi
curl -fL https://gist.githubusercontent.com/ambakshi/51c994271a216016edef/raw/vimrc \
--create-dirs -o $HOME/.config/nvim/init.vim
rm -rf $HOME/.vimrc $HOME/.vim
ln -sfn .config/nvim $HOME/.vim
ln -sfn .config/nvim/init.vim $HOME/.vimrc
mkdir -p $HOME/.vim/{backup,plugged,undo,autoload,tmp/bundle}
curl -fLo $HOME/.vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
if [ -n "$SUDO_USER" ]; then
chown -R $SUIDGID $HOME/.config $HOME/.vim $HOME/.vimrc
if ! install_suexec; then
echo "Run as your user: nvim --headless -c ':PlugInstall' -c 'qall'"
exit 0
fi
if ! command -v git >/dev/null; then
command -v yum >/dev/null && yum install -y git || apt-get install -y git
fi
su-exec $SUIDGID nvim --headless -c ':PlugInstall' -c 'qall' || true
chown -R $SUIDGID $HOME/.config
else
nvim --headless -c ':PlugInstall' -c 'qall' || true
fi
}
install_neovim
setup_user
#!/bin/bash
#
# Installs common packages as static binaries into ~/.local
# to allow for portable container "dev environments"
BASE_URL="${BASE_URL:-http://repo.xcalar.net/deps}"
NVIM_VERSION="0.3.4"
TMUX_VERSION="2.8-8"
RUBY_VERSION="2.3.7"
NODE_VERSION="10.15.0"
CADDY_VERSION="0.11.1_custom1"
FORCE=${FORCE:-false}
PREFIX="${HOME}/.local"
# PREFIX/apps/${app}-${version} contains the app
# PREFIX/bin will have the symlink to the binary form apps/
declare -A VERSIONS=([nvim]=$NVIM_VERSION [tmux]=$TMUX_VERSION [ruby]=$RUBY_VERSION [node]=$NODE_VERSION [caddy]=$CADDY_VERSION)
# shellcheck disable=SC1083
declare -A URLS=([nvim]=${BASE_URL}/nvim-\${version}-linux64.tar.gz
[tmux]=${BASE_URL}/tmux-\${version}.tar.gz
[ruby]=${BASE_URL}/portable-ruby-\${version}.x86_64_linux.bottle.tar.gz
[node]=${BASE_URL}/node-v\${version}-linux-x64.tar.xz
[caddy]=${BASE_URL}/caddy_\${version}_linux_amd64.tar.gz)
ln_r() {
if ln --help | grep -q -- --relative; then
ln -sfnr "$@"
else
ln -sfn "$@"
fi
}
# Install the given app, eg app_install nvim
app_install() {
prog="$1"
version="${VERSIONS[$prog]}"
url="$(eval echo ${URLS[$prog]})"
app_prefix=${PREFIX}/apps/${prog}-${version}
mkdir -p "$app_prefix"
echo >&2 " ==> Installing $1 ($version) from $url"
install_${prog}
}
# Prefix PATH in ~/.bashrc
prefix_path() {
local addpath="$1"
export PATH="${addpath}:$PATH"
if ! grep 'PATH=' ~/.bashrc | grep -q "$addpath"; then
echo >&2 "Adding $addpath to your \$PATH"
echo "export PATH=$addpath:\$PATH" >> ~/.bashrc
fi
}
have_app() {
local version=${VERSIONS[$1]}
if [ -z "$version" ]; then
echo "ERROR: No version of $1 defined!" >&2
exit 1
fi
if $FORCE; then
rm -rf ${PREFIX}/apps/${1}-${version}
fi
test -e ${PREFIX}/apps/${1}-${version}
}
# ** Don't call install_nvim & friends directly **
# Use app_install nvim
install_nvim() {
curl -fsSL $url | tar zxf - --strip-components=1 -C $app_prefix
if test -e $HOME/.vimrc && ! test -L $HOME/.vimrc; then
mv -v ~/.vimrc ~/vimrc.bak
echo >&2 "WARNING: Renamed $HOME/.vimrc to $HOME/vimrc.bak"
fi
if test -e $HOME/.vim && ! test -L $HOME/.vim; then
mv -v ~/.vim ~/vim.bak
echo >&2 "WARNING: Renamed $HOME/.vim to $HOME/vim.bak"
fi
mkdir -p $HOME/.config/nvim
touch $HOME/.config/nvim/init.vim
ln -sfn .config/nvim $HOME/.vim
ln -sfn .config/nvim/init.vim $HOME/.vimrc
ln_r $app_prefix/bin/nvim $PREFIX/bin/
ln -sfn nvim $PREFIX/bin/vim
ln -sfn nvim $PREFIX/bin/vi
echo -e 'exec nvim -d "$@"' > $PREFIX/bin/vimdiff
chmod +x $PREFIX/bin/vimdiff
}
install_tmux() {
curl -fsSL "$url" | tar zxf - -C ${app_prefix}
ln_r ${app_prefix}/bin/tmux ${PREFIX}/bin/
ln_r ${app_prefix}/bin/tmux-mem-cpu-load ${PREFIX}/bin/
}
install_caddy() {
curl -fsSL "$url" | tar zxf - -C ${app_prefix}
ln_r ${app_prefix}/caddy ${PREFIX}/bin/
}
install_ruby() {
curl -fsSL "$url" | tar zxf - -C $app_prefix --strip-components=2
for tool in ruby gem bundle bundler ri rdoc irb; do
ln_r ${app_prefix}/bin/${tool} ${PREFIX}/bin/
done
export PATH="${app_prefix}/bin:$PATH"
echo >&2 "==> $(command -v ruby)"
${app_prefix}/bin/ruby --version 1>&2
${app_prefix}/bin/gem install --no-ri --no-rdoc bundler
prefix_path "${app_prefix}/bin"
}
# shellcheck disable=SC1083,SC2016
install_node() {
cat > ~/.npmrc << 'EOF'
registry=http://registry.npmjs.org/
prefix=~/.npm-global
EOF
curl -fsSL "$url" | tar Jxf - -C ${app_prefix} --strip-components=1
for tool in node npm npx; do
ln_r ${app_prefix}/bin/${tool} ${PREFIX}/bin/
done
prefix_path "${HOME}/.npm-global/bin"
}
[ $# -gt 0 ] || set -- --all
while [ $# -gt 0 ]; do
cmd="$1"
shift
case "$cmd" in
-f | --force)
FORCE=true
;;
-d | --directory | --prefix)
PREFIX="$1"
shift
;;
--install-*)
prog="${cmd#--install-}"
if ! have_app $prog; then
echo >&2 "==> Installing $prog"
mkdir -p ${PREFIX}/bin
app_install ${prog}
else
echo >&2 "==> Already have $prog"
fi
;;
--all)
mkdir -p ${PREFIX}/bin ${PREFIX}/apps/
have_app nvim || app_install nvim
have_app tmux || app_install tmux
have_app caddy || app_install caddy
have_app ruby || app_install ruby
have_app node || app_install node
;;
-h | --help)
echo >&2
echo >&2 -n " Usage: $0 [-f|--force] [--all] [-d|--directory|--prefix dir] ["
grep -Eow '^install_([a-z]+)' $0 | sed -r 's/^install_/--install-/g' | tr '\n' ' ' >&2
echo >&2 "]"
echo >&2
exit 1
;;
esac
done
prefix_path "${PREFIX}/bin"
echo >&2
echo >&2 "Please restart your shell via 'exec \$SHELL -l' or 'source ~/.bashrc'"
echo >&2
# ` is an interesting key for a prefix
# set-option -g prefix `
#
# ChangeLog:
# 10/27/2021 Tmux 3.2a
# 05/19/2017 Remove utf-8 option
# 06/01/2017 Add allow-rename off
set-option -g prefix C-a
unbind-key C-b
set-option -g default-terminal "screen-256color"
## set-option -g mouse-select-pane on
set-option -g status-keys vi
set-option -g bell-action any
set-option -g set-titles on
set-option -g set-titles-string '#H:#S.#I.#P #W #T' # window number,program name,active (or not)
set-option -g visual-bell off
bind-key C-a last-window
bind-key ` last-window
bind-key a send-prefix
# we might need ` at some point, allow switching
# we can also send the prefix char with `-a
bind-key F11 set-option -g prefix C-a
bind-key F12 set-option -g prefix `
# 0 is too far from ` ;)
set -g base-index 1
setw -g mode-keys vi
set -g mouse on
setw -g monitor-activity on
#bind-key -t vi-copy 'v' begin-selection
#bind-key -t vi-copy 'y' copy-selection
bind e previous-window
bind f next-window
bind E swap-window -t -1
bind F swap-window -t +1
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# window splitting
unbind %
bind | split-window -h -c '#{pane_current_path}'
unbind '"'
bind - split-window -v -c '#{pane_current_path}'
## new-window should go to home dir
# unbind 'c'
# bind c new-window -c '#{pane_current_path}'
# screen style
# bind S split-window -v
unbind ","
bind-key '"' command-prompt -I '#W' "rename-window '%%'"
#set-option -g status-utf8 on
set-option -g status-justify left
set-option -g status-bg black
set-option -g status-fg white
set-option -g status-left-length 40
set-option -g status-right-length 80
#set-option -g pane-active-border-fg green
#set-option -g pane-active-border-bg black
set-option -g pane-active-border-style fg=green
set-option -g pane-active-border-style bg=black
set-option -g pane-border-style fg=white
set-option -g pane-border-style bg=black
set-option -g message-style fg=black
set-option -g message-style bg=green
#setw -g mode-bg black
# don't wait for an escape sequence after hitting
# Esc. fixes insert mode exit lag in vim
set -sg escape-time 0
# Don't let tmux rename your windows
set-option -g allow-rename off
setw -g window-status-style bg=black
setw -g window-status-current-style fg=green
setw -g window-status-bell-attr default
setw -g window-status-bell-style fg=red
#setw -g window-status-content-attr default
#setw -g window-status-content-fg yellow
setw -g window-status-activity-attr default
setw -g window-status-activity-style fg=yellow
set -g status-left '#[fg=red]#H#[fg=green]:#[fg=white]#S #[fg=green]][#[default]'
set -g status-interval 5
#set -g status-right '#[fg=green]][#[fg=white] #(tmux-mem-cpu-load 5 4) #[fg=green]][ #[fg=yellow]%H:%M#[default]'
set -g status-right "#S #[fg=green,bg=black]#(tmux-mem-cpu-load --interval 5 -g 5)#[default]"
is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?)(diff)?$"'
bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind -n C-\\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
set -g history-limit 1000000000
bind r source-file ~/.tmux.conf
"
" Amit Bakshi's vimrc. The first time you have to
" run ':PlugInstall'
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('~/.vim/plugged')
Plug 'tpope/vim-sensible' " sane defaults
" Editing
Plug 'sjl/gundo.vim'
" Plug 'dracula/vim'
" Plug 'Valloric/YouCompleteMe' " cd ~/.vim/bundle/YouCompleteMe && ./install.sh
Plug 'christoomey/vim-tmux-navigator'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'fatih/vim-hclfmt'
Plug 'b4b4r07/vim-hcl'
Plug 'sealeg/vim-kickstart'
" Plug 'elzr/vim-json'
" Plug 'xolox/vim-misc'
" Plug 'xolox/vim-notes'
" Plug 'scrooloose/nerdcommenter'
" Plug 'SirVer/ultisnips'
" Plug 'honza/vim-snippets'
" Speed up autocomplete!
Plug 'Konfekt/FastFold'
" Navigation
Plug 'kien/ctrlp.vim'
if executable('ctags')
Plug 'vim-scripts/taglist.vim'
Plug 'majutsushi/tagbar'
endif
" Plug 'scrooloose/nerdtree'
Plug 'Lokaltog/vim-easymotion'
Plug 'junegunn/vim-easy-align'
" Syntax/programming support
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'vim-syntastic/syntastic'
Plug 'rodjek/vim-puppet'
Plug 'vim-scripts/spec.vim'
Plug 'fatih/vim-go', { 'for': 'go' }
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'PProvost/vim-ps1', { 'for': 'ps1' }
"Plug 'tpope/vim-markdown.git'
"Plug 'jtratner/vim-flavored-markdown'
" Plug 'gabrielelana/vim-markdown'
Plug 'markcornick/vim-bats'
Plug 'ekalinin/Dockerfile.vim'
" Plug 'Rip-Rip/clang_complete'
Plug 'hashivim/vim-terraform'
Plug 'hashivim/vim-packer'
Plug 'pearofducks/ansible-vim'
Plug 'GutenYe/json5.vim'
Plug 'hashivim/vim-hashicorp-tools'
Plug 'pboettch/vim-cmake-syntax'
if executable('shfmt')
Plug 'z0mbix/vim-shfmt', { 'for': 'sh' }
endif
if executable('rg')
Plug 'jremmen/vim-ripgrep'
endif
Plug 'google/vim-jsonnet'
" Colors
" Plug 'altercation/vim-colors-solarized'
Plug 'fatih/molokai'
" Plug 'bling/vim-airline'
if empty($TMUX)
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
endif
" Git
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'mattn/webapi-vim'
Plug 'mattn/gist-vim'
if executable('editorconfig')
Plug 'editorconfig/editorconfig-vim'
endif
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'chrisbra/Recover.vim'
" ** All of your Plugs must be added before the following line **
" call vundle#end() " required
call plug#end()
" syntax enable
" filetype plugin indent on
let g:solarized_termcolors = 256
let g:rehash256 = 1 " alternate molokai version
if !has('nvim')
set background=dark " molokai sets this inside their script
endif
silent! colorscheme molokai " solarized
if !has('nvim')
if &term =~ "xterm" || &term =~ "screen"
" set t_RV=^[[c " Some bullshit terminall string holdover from windows
set ttymouse=xterm2 t_Co=256
endif
if has('mouse')
set mouse=a
endif
endif
set encoding=utf-8
set history=10000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
if has("persistent_undo")
set undofile " keep a persistent backup file
set undodir=~/.vim/undo,~/.tmp,~/tmp
endif
set backup
set writebackup
set backupdir=~/.vim/backup
set directory=.,~/.vim/tmp
set backspace=eol,start,indent
set incsearch hlsearch ignorecase smartcase showmatch
set expandtab smarttab shiftwidth=4 shiftround softtabstop=4 tabstop=4
set smartindent autoindent copyindent cindent
set lbr tw=140 autoindent
set noerrorbells
set virtualedit=onemore
set scrolloff=10 sidescrolloff=10
set winminheight=0
set noshowcmd title cmdheight=1
set laststatus=2 showmode
set tags=./tags,tags,../tags,../../tags,$XLRDIR/tags,$XLRINFRADIR/tag " ../../../tags,../../../../tag,~/tags,/usr/src/tags,/usr/include/tags,/usr/local/include/tags,$GOPATH/src/**/tags,$HOME/tags
set path=.;./include;**,/usr/local/include/sys;/usr/include/sys;/usr
set dictionary=/usr/share/dict/words
set viminfo='20,\"80 " read/write a .viminfo file, don't store more
" than 80 lines of registers
set wildmenu " make tab completion for files/buffers act like bash
set wildmode=list:full " show a list when pressing tab and complete
" first full match
set wildignore=*.swp,*.bak,*.pyc,*.class,~*
set ttyfast " always use a fast terminal
set ruler
set title " change the terminal's title
set visualbell t_vb= " don't beep
set noerrorbells " don't beep
set showcmd " show (partial) command in the last line of the screen
" this also shows visual selection info
set modeline " disable mode lines (security measure)
set modelines=2 " OSX's default vimrc sets modeline*S* to 0. Retarded
set nocursorline " underline the current line, for quick orientation
set nowrap
set wrapmargin=0 textwidth=124
set formatoptions+=l " Don't wrap when typing on an existing line
set foldmethod=manual
set foldlevelstart=20
""""""""""""""""""""""""""""""
" Global remappings and leader
""""""""""""""""""""""""""""""
let mapleader=","
let g:mapleader=","
nnoremap ; :
nnoremap j gj " this is so when you go up/down on a wrapped line it
nnoremap k gk " doesn't obey some ancient line number rule
nnoremap / /\v
vnoremap / /\v
nnoremap <leader><space> :noh<cr>
nnoremap <tab> %
vnoremap <tab> %
" FIXME: Doesn't seem to work in vim on EL6/7
" if !has("nvim")
" if v:version > 703
" set cryptmethod=blowfish2
" endif
" endif
" Cursor shape change depending on the mode like in gvim. Only in tmux.
" if !empty($TMUX)
" let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
" let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
" inoremap <special> <Esc> <Esc>h
" don't blink the cursor
" set guicursor+=i:blinkwait0
" endif
""""""""""""""""""""""""""""""
" PLUGINS
""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" Gist
""""""""""""""""""""""""""""""
" If you want to show your private gists with ":Gist -l":
let g:gist_show_privates = 1
let g:gist_post_private = 1
let g:gist_post_anonymous = 1
let g:gist_get_multiplefile = 1
" let g:gist_list_vsplit = 1
" Only :w! updates a gist.
let g:gist_update_on_write = 2
""""""""""""""""""""""""""""""
" Tagbar
""""""""""""""""""""""""""""""
nnoremap <leader>l :TagbarToggle<CR>
" let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
let Tlist_Display_Prototype=1
let Tlist_Display_Tag_Scope=0
let Tlist_Use_Right_Window=1
let Tlist_Auto_Highlight_Tag = 1
let Tlist_Auto_Update = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Highlight_Tag_On_BufEnter = 1
let Tlist_Use_SingleClick = 1
" Override how taglist does javascript
let g:tlist_javascript_settings = 'javascript;f:function;c:class;m:method;p:property;v:global'
let g:ctags_statusline=1
" }}
" let g:tagbar_left = 1
let g:tagbar_usearrows = 1
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
""""""""""""""""""""""""""""""
" syntastic
""""""""""""""""""""""""""""""
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 0
""""""""""""""""""""""""""""""
" YouCompleteMe
""""""""""""""""""""""""""""""
"b:ycm_largefile=1
"b:ycm_largefile=1
" let g:ycm_min_num_of_chars_for_completion=12
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
let g:ycm_extra_conf_globlist = ['!~/xcalar/.ycm_extra_conf.py']
""""""""""""""""""""""""""""""
" ailirline
""""""""""""""""""""""""""""""
" You need a special bitmap font for this mode.
let g:airline_powerline_fonts = 1
let g:Powerline_symbols = "fancy"
let g:bufferline_echo = 0
let g:airline_theme = 'powerlineish'
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#syntastic#enabled = 1
" let g:rehash256 = 1
"
" https://github.com/bling/vim-airline/wiki/FAQ
" if !exists('g:airline_symbols')
" let g:airline_symbols = {}
" endif
" let g:airline_symbols.space = "\ua0"
""""""""""""""""""""""""""""""
" EasyMotion
""""""""""""""""""""""""""""""
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" let g:EasyMotion_use_upper = 1
" let g:EasyMotion_keys = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ;'
let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
" let g:EasyMotion_inc_highlight = 0
let g:EasyMotion_do_shade = 1
let g:EasyMotion_smartcase = 1
" let g:EasyMotion_move_highlight = 1
" Bidirectional: nmap <Leader>w <Plug>(easymotion-bd-w)
nmap <Leader>w <Plug>(easymotion-w)
nmap s <Plug>(easymotion-s2)
nmap t <Plug>(easymotion-t2)
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
" Replace default search? Nope.
" map / <Plug>(easymotion-sn)
" omap / <Plug>(easymotion-tn)
" These `n` & `N` mappings are options. You do not have to map `n` & `N` to
" EasyMotion. Without these mappings, `n` & `N` works fine. (These mappings
" just provide different highlight method and have some other features )
"
" map n <Plug>(easymotion-next)
" map N <Plug>(easymotion-prev)
""""""""""""""""""""""""""""""
" EasyAlign
""""""""""""""""""""""""""""""
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
""""""""""""""""""""""""""""""
" UltiSnips
""""""""""""""""""""""""""""""
let g:UltiSnipsExpandTrigger="<c-i>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
""""""""""""""""""""""""""""""
" grep/ag/ctrl-p
""""""""""""""""""""""""""""""
" bind K to grep word under cursor
nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
""""""""""""""""""""""""""""""
" Ansible
""""""""""""""""""""""""""""""
au BufRead,BufNewFile */ansible/*.yml set filetype=yaml.ansible
au BufRead,BufNewFile */ansible/*.yaml set filetype=yaml.ansible
au BufRead,BufNewFile */playbooks/*.yml set filetype=yaml.ansible
au BufRead,BufNewFile */playbooks/*.yaml set filetype=yaml.ansible
au BufRead,BufNewFile */tasks/*.yml set filetype=yaml.ansible
au BufRead,BufNewFile */tasks/*.yaml set filetype=yaml.ansible
au BufRead,BufNewFile */roles/**/*.yml set filetype=yaml.ansible
au BufRead,BufNewFile */roles/**/*.yaml set filetype=yaml.ansible
let g:ansible_unindent_after_newline = 1
let g:ansible_extra_syntaxes = "sh.vim ruby.vim"
let g:ansible_extra_keywords_highlight = 1
let g:ansible_attribute_highlight = "ob"
let g:ansible_name_highlight = 'd'
let g:ansible_with_keywords_highlight = 'Constant'
let g:ansible_template_syntaxes = { '*.yaml.j2': 'yaml.ansible', '*.tf.j2': 'hcl', '*.nomad.j2': 'hcl', '*.hcl.j2': 'hcl', '*.ps1.j2': 'ps1' }
""""""""""""""""""""""""""""""
" KEYBOARD
""""""""""""""""""""""""""""""
" Move between windows easier
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
map <C-L> <C-W>l<C-W>_
map <C-H> <C-W>h<C-W>_
map <C-K> <C-W>k<C-W>_
" Wrapped lines goes down/up to next row, rather than next line in file.
nnoremap j gj
nnoremap k gk
" Better 'n' next highlight
" nnoremap <silent> n n:call HLNext(0.4)<cr>
" nnoremap <silent> N n:call HLNext(0.4)<cr>
function! HLNext (blinktime)
set invcursorline
redraw
exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm'
set invcursorline
redraw
endfunction
" Turn off highlighting in insert mode
autocmd InsertEnter * :setlocal nohlsearch
autocmd InsertLeave * :setlocal hlsearch
""""""""""""""""""""""""""""""
" Special highlighting stuff
""""""""""""""""""""""""""""""
set diffopt+=iwhite
highlight DiffAdd term=reverse cterm=bold ctermbg=green ctermfg=white
highlight DiffChange term=reverse cterm=bold ctermbg=cyan ctermfg=black
highlight DiffText term=reverse cterm=bold ctermbg=gray ctermfg=black
highlight DiffDelete term=reverse cterm=bold ctermbg=red ctermfg=black
" Mark 81st column in red only when text is present
" via: Damian Conway, 'More Instantly Better Vim'
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
""""""""""""""""""""""""""""""
" Filetype triggers
""""""""""""""""""""""""""""""
autocmd FileType go,sh,markdown,puppet,python,make,c,cpp,java,php,ruby autocmd BufWritePre <buffer> :%s/\s\+$//e
" Save a backup file with the date in it
augroup backuprename
au!
au BufWritePre * let &bex = '~' . strftime("%Y%m%d-%H%M%S") . '~'
augroup end
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
autocmd FileType ruby setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType yaml setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType puppet setlocal tabstop=2 expandtab shiftwidth=2 softtabstop=2
" augroup markdown
" au!
" au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown
" augroup end
" au VimEnter * NERDTreeToggle
" nmap <F3> :NERDTreeToggle<CR>
" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" Remove trailing whitespace
if has("autocmd")
autocmd BufWritePre * :%s/\s\+$//e
endif
" Golang
"
"
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage)
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
au FileType go nmap <Leader>s <Plug>(go-implements)
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <Leader>e <Plug>(go-rename)
let g:go_auto_type_info = 1
let g:go_auto_sameids = 1
let g:go_fmt_experimental = 1
let g:go_fmt_command = "goimports"
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
""""""""""""""""""""""""""""""
" shfmt
""""""""""""""""""""""""""""""
let g:syntastic_python_flake8_exec = 'python3'
let g:shfmt_extra_args = '-i 4 -bn -s -ci'
let g:shfmt_fmt_on_save = 0
"""""""""""""""""""""""""""""
" Gopass
"""""""""""""""""""""""""""""
au BufNewFile,BufRead /dev/shm/gopass.* setlocal noswapfile nobackup noundofile
"""""""""""""""""""""""""""""
" Vault
"""""""""""""""""""""""""""""
au BufNewFile,BufRead .vault-token setlocal noswapfile nobackup noundofile
""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" Local customizations
""""""""""""""""""""""""""""""
if filereadable(expand("\~/.vimrc.local"))
source \~/.vimrc.local
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment