diff options
author | Adam Hovorka <[email protected]> | 2017-07-10 11:39:20 -0600 |
---|---|---|
committer | Adam Hovorka <[email protected]> | 2017-07-10 11:39:20 -0600 |
commit | 6b4563f569454c12aded584db4330f707bc55c3d (patch) | |
tree | 459a19255bc73f8fbbf1dd6b4f0c8e8a82fc8523 |
Initial commit
-rw-r--r-- | base/.vimrc | 143 | ||||
-rwxr-xr-x | stowsh | 182 |
2 files changed, 325 insertions, 0 deletions
diff --git a/base/.vimrc b/base/.vimrc new file mode 100644 index 0000000..ebdcd21 --- /dev/null +++ b/base/.vimrc @@ -0,0 +1,143 @@ +set nocompatible + +set modelines=0 " for security + +set encoding=utf-8 + +set mouse="" + +set backspace=indent,eol,start + +au FocusLost * :wa + +" Leader ====---- +nnoremap ,, , +let mapleader="," +nnoremap <leader>; ; +nnoremap ; : + +" Highlighting ====---- +syntax on +filetype plugin indent on + +set t_Co=256 " enable 256-color mode. +if &t_Co >= 256 || has("gui_running") + "colorscheme mustang + "colorscheme desert " set colorscheme +endif +if &t_Co > 2 || has("gui_running") + " switch syntax highlighting on, when the terminal has colors + syntax on +endif + +" Indentation ====---- +set shiftwidth=2 +set tabstop=2 +set expandtab +set shiftround " use multiple of shiftwidth with '<' and '>' +set autoindent +set copyindent " copy the previous line's indentation + +" Search ====---- +set incsearch +set hlsearch +set wrapscan +set ignorecase " ignore case when searching +set smartcase " ignore case if search pattern is all lowercase, + " case-sensitive otherwise + +nnoremap <leader><space> :noh<cr> + +" Case insensitive +nnoremap * /\<<C-R>=expand('<cword>')<CR>\><CR> +nnoremap # ?\<<C-R>=expand('<cword>')<CR>\><CR> + +set showmatch +nnoremap <tab> % +vnoremap <tab> % + +" Screen ====---- +"set nowrap +set wrap +"set textwidth=79 +"set formatoptions=tqrn1 +set colorcolumn=85 +set ruler +"set number " always show line numbers +set relativenumber +set laststatus=2 +set cursorline +"set showmode +set showcmd +set title " change the terminal's title +set scrolloff=3 + +set visualbell " don't beep +set noerrorbells " don't beep + +set list +set listchars=tab:>.,trail:.,extends:#,nbsp:. +"autocmd filetype html,xml set listchars-=tab:>. + +set wildmenu +set wildmode=longest:full,full +set wildignore=*.swp,*.bak,*.pyc,*.class + +set ttyfast + +" Stop using arrow keys ====---- +nnoremap <up> <nop> +nnoremap <down> <nop> +nnoremap <left> <nop> +nnoremap <right> <nop> +inoremap <up> <nop> +inoremap <down> <nop> +inoremap <left> <nop> +inoremap <right> <nop> + +" nnoremap j gj +" nnoremap k gk + +" Splits ====---- +nnoremap <leader>w <C-w>v<C-w>l split +nnoremap <C-h> <C-w>h +nnoremap <C-j> <C-w>j +nnoremap <C-k> <C-w>k +nnoremap <C-l> <C-w>l + +" History ====---- +set history=1000 " remember more commands and search history +set undolevels=1000 " use many muchos levels of undo + +if !isdirectory($HOME."/.vim") + call mkdir($HOME."/.vim", "", 0770) +endif +if !isdirectory($HOME."/.vim/undo-dir") + call mkdir($HOME."/.vim/undo-dir", "", 0700) +endif +set undodir=~/.vim/undo-dir +set undofile +" !!!! ADD THIS TO CRONTAB +" 43 0 * * 3 find /home/adam/.vim/undo-dir -type f -mtime +90 -delete + +set nobackup +set noswapfile " Note: swap helps large files. + +" Custom mappings ====---- + +" Quickly edit/reload the vimrc file +nnoremap <silent> <leader>ev :e $MYVIMRC<CR> +nnoremap <silent> <leader>sv :so $MYVIMRC<CR> + +set pastetoggle=<F2> + +nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR> " strip trailing whitespace +nnoremap <leader>ft Vatzf " fold tag +nnoremap <leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:noh<CR> " sort CSS +nnoremap <leader>q gqip " re-hardwrap +nnoremap <leader>v V`] " select pasted + +vnoremap Q gq +nnoremap Q gqap + +cnoremap w!! w !sudo tee % >/dev/null @@ -0,0 +1,182 @@ +#!/usr/bin/env bash + +_runcommands() { + local prefix='' + if [[ $DRYRUN == 1 ]] || [[ $VERBOSE -gt 1 ]]; then + echo "$@" + fi + if [[ $DRYRUN != 1 ]]; then + eval "$@" + fi +} + +echoerr() { + printf "%s\n" "$*" >&2; +} + +deperr() { + echoerr "stowsh requires $1" +} + +stowsh_setpaths() { + if command -v grealpath >/dev/null 2>&1; then + rpcmd="grealpath" + elif command -v realpath >/dev/null 2>&1; then + rpcmd="realpath" + else + deperr "GNU coreutils" + return 1 + fi + if ! strings "$(which "$rpcmd")" | grep -q "GNU coreutils" ; then + deperr "GNU coreutils" + return 1 + fi + if command -v gfind >/dev/null 2>&1; then + findcmd="gfind" + elif command -v find >/dev/null 2>&1; then + findcmd="find" + else + deperr "GNU findutils" + return 1 + fi + if ! strings "$(which "$findcmd")" | grep -q "GNU findutils" ; then + deperr "GNU findutils" + return 1 + fi +} + +stowsh_install() { + stowsh_setpaths || return 1 + local pkg=$1 + local target + target=$( "$rpcmd" "${2-$PWD}" ) + local commands=() + + ( + cd "$pkg" || return 1 + dirs="$($findcmd . -mindepth 1 -type d | sed "s|./||")" + for d in $dirs ; do + commands+=("mkdir -p '$target/$d'") + done + + local files + files="$($findcmd . -type f -or -type l | sed "s|./||")" + for f in $files ; do + local targetf="$target/$f" + local thisdir + thisdir=$(dirname "$targetf") + local relative + relative=$($rpcmd "$f" --relative-to="$thisdir" --canonicalize-missing) + if [[ ! -f "$targetf" ]] ; then + commands+=("ln -s '$relative' '$targetf'") + else + echoerr "$targetf already exists." + if [[ ! $SKIP -eq 1 ]]; then + echoerr "Aborting. Rerun with the -s flag to skip errors."; + return + fi + fi + done + for cmd in "${commands[@]}"; do + _runcommands "$cmd" + done; + ) +} + +stowsh_uninstall() { + stowsh_setpaths || return 1 + local pkg=$1 + local target + target=$( "$rpcmd" "${2-$PWD}" ) + local commands=() + + ( + cd "$pkg" || return 1 + local files + files="$($findcmd . -type f -or -type l | sed "s|./||")" + for f in $files ; do + local targetf="$target/$f" + if [[ $($rpcmd "$targetf") == $(realpath "$f") ]] ; then + commands+=("rm '$targetf'") + elif [[ -f "$targetf" ]] ; then + echoerr "$targetf does not point to to $(realpath "$f")." + if [[ ! $SKIP -eq 1 ]]; then + echoerr "Aborting. Rerun with the -s flag to skip errors."; + return + fi + elif [[ ! -f "$targetf" ]] ; then + echoerr "$targetf does not exist. Nothing to do." + if [[ ! $SKIP -eq 1 ]]; then + echoerr "Aborting. Rerun with the -s flag to skip errors."; + return + fi + fi + done + + dirs="$($findcmd . -mindepth 1 -type d | sed "s|./||")" + for d in $dirs ; do + commands+=("[[ -d '$target/$d' ]] && $findcmd '$target/$d' -type d -empty -delete") + done + for cmd in "${commands[@]}"; do + _runcommands "$cmd" + done; + ) +} + +stowsh_help() { + echo "Usage: $0 [-D] [-n] [-s] [-v[v]] [-t TARGET] PACKAGES..." +} + +if [ "$0" = "$BASH_SOURCE" ]; then + UNINSTALL=0 + DRYRUN=0 + SKIP=0 + TARGET="$PWD" + PACKAGES=() + while [[ "$@" ]]; do + if [[ $1 =~ ^- ]]; then + OPTIND=1 + while getopts ":vhDsnt:" opt; do + case $opt in + h) + stowsh_help + exit 0 + ;; + D) UNINSTALL=1 + ;; + n) DRYRUN=1 + ;; + s) SKIP=1 + ;; + v) VERBOSE=$((VERBOSE + 1)) + ;; + t) TARGET="$OPTARG" + ;; + *) echo "'$OPTARG' is an invalid option/flag" + exit 1 + ;; + esac + done + shift $((OPTIND-1)) + else + PACKAGES+=("$1") + shift + fi + done + + if [[ ${#PACKAGES[@]} -eq 0 ]] ; then + stowsh_help + exit 1 + fi + + for i in ${!PACKAGES[*]}; do + pkg=${PACKAGES[$i]} + if [[ $UNINSTALL -eq 1 ]]; then + if [[ $VERBOSE -gt 0 ]] ; then echoerr "uninstalling $pkg from $TARGET" ; fi + stowsh_uninstall "$pkg" "$TARGET" + else + if [[ $VERBOSE -gt 0 ]] ; then echoerr "installing $pkg to $TARGET" ; fi + stowsh_install "$pkg" "$TARGET" + fi + done +fi |