From 34910ecb8bcfa320e2ca030c6219e438418b2efc Mon Sep 17 00:00:00 2001 From: Evan Thomas Date: Tue, 18 Aug 2020 17:38:09 -0500 Subject: [PATCH] Update 8/18/2020 --- .bashrc | 1 + .vim/.vimrc | 40 +++++++++++++++++++++----------- .vim/plugin/mystuff/header.vim | 19 +++++++++++++++ .vim/plugin/mystuff/snippets.vim | 1 + scripts/bootstrap-python | 10 +++++++- scripts/pihole | 31 +++++++++++++++++++++++++ scripts/quickdb | 6 +++++ scripts/shuffle | 8 +++++++ scripts/stopwatch | 4 ++++ scripts/tfwrapper | 3 +++ scripts/timer | 2 ++ scripts/today | 1 + 12 files changed, 111 insertions(+), 15 deletions(-) create mode 100644 .vim/plugin/mystuff/header.vim create mode 100644 scripts/pihole create mode 100755 scripts/quickdb create mode 100755 scripts/shuffle create mode 100755 scripts/stopwatch create mode 100755 scripts/timer create mode 100755 scripts/today diff --git a/.bashrc b/.bashrc index 367e0fd..3437a59 100644 --- a/.bashrc +++ b/.bashrc @@ -38,6 +38,7 @@ PATH="${PATH}:$HOME/scripts/git-scripts" PATH="${PATH}:$PYENV_ROOT/bin" PATH="${PATH}:/usr/local/sbin" PATH="$PYENV_ROOT/bin:${PATH}" +PATH="${PATH}:/home/evan/github.com/tempoautomation/talos-tools" export PATH # ================================= ALIASES ================================= diff --git a/.vim/.vimrc b/.vim/.vimrc index fd35d42..ebef621 100644 --- a/.vim/.vimrc +++ b/.vim/.vimrc @@ -99,13 +99,6 @@ let g:SignatureForceRemoveGlobal = 1 " See https://github.com/kshenoy/vim-signat " Plug 'https://github.com/jiangmiao/auto-pairs' call plug#end() - -" - - - - - autocmd BufRead,BufNewFile *go setlocal filetype=go set noswapfile @@ -280,14 +273,27 @@ let g:fzf_layout = {'down': '45%'} command! -bang -nargs=* Ag \ call fzf#vim#ag(, fzf#vim#with_preview('right:35%')) + +" command! -nargs=* -complete=dir Rg +" \ call fzf#vim#grep( +" \ "rg --column --line-number --no-heading --fixed-strings --smart-case --hidden --color=always --glob '!.git/**' --glob '!.hg/**' --glob '!**/*.ico' --glob '!**/*.png' --glob '!**/*.jpg' --glob '!**/*.jpeg' --glob '!**/*.zip' --glob '!**/*.tar.gz' --glob '!**/*.gif' --glob '!**/*.avi' --glob '!**/*.mp4' --glob '!**/*.mp3' --glob '!**/*.ogg' --glob '!**/*.tgz' --glob '!**/*.gz' --glob '!**/*.ctg.z' --glob '!**/*.bcmap' "., 1, +" \ fzf#vim#with_preview('right:35%'), +" \ ) + +command! -nargs=* -complete=dir Rg + \ call fzf#vim#grep( + \ "rg --column --line-number --no-heading --fixed-strings --smart-case --hidden --color=always "., 1, + \ fzf#vim#with_preview('right:35%'), + \ ) + command! -bang -nargs=* Lines \ call fzf#vim#lines(, fzf#vim#with_preview('right:35%')) " Immediately trigger a search for the current keyword if there is one -nnoremap g (expand("") ==? "") ? ":Ag " : ":Ag \\" +nnoremap g (expand("") ==? "") ? ":Rg " : ":Rg \\" " Immediately trigger a search for the current selection if there is one -xnoremap g "zy:exe "Ag ".@z."" +xnoremap g "zy:exe "Rg ".@z."" let g:prettier#exec_cmd_path = "~/.config/yarn/global/node_modules/.bin/prettier" let g:prettier#exec_cmd_async = 1 @@ -400,6 +406,9 @@ set clipboard^=unnamedplus " from https://stackoverflow.com/questions/4256697/vim-search-and-highlight-but-do-not-jump nnoremap s :let @/='\<=expand("")\>':set hls +xnoremap s "zy:let @/='z':set hls +" xnoremap s "/y:let @/='z':set hls +" xnoremap s "zy:let @/='\<z' nnoremap h :set nohls @@ -420,8 +429,11 @@ xnoremap gn :g/./norm nnoremap gvn :v/./norm xnoremap gvn :v/./norm -" function! Black() -" silent execute ":!black " . expand("%:p") -" silent execute ":e" -" endfunction -" command! -nargs=0 Black call Black() +command! -nargs=0 FoldPython :%g/^\s*def/norm f)jzfii + +command! -nargs=* JQ :%!jq +command! -nargs=* Jq :%!jq + +command! -nargs=1 Ft :set ft= + +command! -nargs=0 Ws :w !sudo tee % diff --git a/.vim/plugin/mystuff/header.vim b/.vim/plugin/mystuff/header.vim new file mode 100644 index 0000000..253b547 --- /dev/null +++ b/.vim/plugin/mystuff/header.vim @@ -0,0 +1,19 @@ +function! MakeHeader() + let l:text = trim(getline('.')) + let l:textlen = strlen(l:text) + let l:headerlen = 79 + let l:row1 = repeat(join(['#'], ''), l:headerlen) + let l:row2BeginLen = (l:headerlen - l:textlen - 2 + 1) / 2 + let l:row2EndLen = (l:headerlen - l:textlen - 2) / 2 + let l:row2 = repeat(join(['#'], ''), l:row2BeginLen) . + \ ' ' . l:text . ' ' . + \ repeat(join(['#'], ''), l:row2EndLen) + + call append(line('.'), l:row1) + call append(line('.'), l:row2) + call append(line('.'), l:row1) + " for some reason internet says not to use normal in vimscript + normal! dd +endfunction + +command! -nargs=0 Header call MakeHeader() diff --git a/.vim/plugin/mystuff/snippets.vim b/.vim/plugin/mystuff/snippets.vim index f403992..d00287b 100644 --- a/.vim/plugin/mystuff/snippets.vim +++ b/.vim/plugin/mystuff/snippets.vim @@ -10,6 +10,7 @@ inoremap hist !!cat ~/.vim/snippets/hist}i inoremap tbl !!cat ~/.vim/snippets/tbl}}}oo inoremap table !!cat ~/.vim/snippets/tbl}}}oo inoremap prof !!cat ~/.vim/snippets/prof}o0i +inoremap sep ------------------------------------------------------------------------------ inoremap pset \pset null 'Ø' diff --git a/scripts/bootstrap-python b/scripts/bootstrap-python index 916bdb4..0e9f3c4 100755 --- a/scripts/bootstrap-python +++ b/scripts/bootstrap-python @@ -1,6 +1,14 @@ +#!/bin/bash + /home/evan/.pyenv/shims/python3.8 -m venv venv -echo "source venv/bin/activate" > .envrc +echo "source venv/bin/activate" >> .envrc source venv/bin/activate pip install flake8 pip install mypy pip install black +pip install jedi + +cat <> pyproject.toml +[tool.black] +line-length = 79 +EOF diff --git a/scripts/pihole b/scripts/pihole new file mode 100644 index 0000000..53d22c2 --- /dev/null +++ b/scripts/pihole @@ -0,0 +1,31 @@ +#!/bin/bash + +# https://hub.docker.com/r/diginc/pi-hole/ + +# IP_LOOKUP="$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')" # May not work for VPN / tun0 +# IPv6_LOOKUP="$(ip -6 route get 2001:4860:4860::8888 | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}')" # May not work for VPN / tun0 +# IP="${IP:-$IP_LOOKUP}" # use $IP, if set, otherwise IP_LOOKUP +# IPv6="${IPv6:-$IPv6_LOOKUP}" # use $IPv6, if set, otherwise IP_LOOKUP +# DOCKER_CONFIGS="$(pwd)" # Default of directory you run this from, update to where ever. + +ServerIP=$(curl api.ipify) +WEBPASSWORD=muttley1 +DOCKER_CONFIGS=$(pwd) + +echo "### Make sure your IPs are correct, hard code ServerIP ENV VARs if necessary\nIP: ${IP}\nIPv6: ${IPv6}" +docker run -d \ + --name pihole \ + -p 53:53/tcp -p 53:53/udp \ + -p 67:67/udp \ + -p 80:80 \ + -p 443:443 \ + -v "${DOCKER_CONFIGS}/pihole/:/etc/pihole/" \ + -v "${DOCKER_CONFIGS}/dnsmasq.d/:/etc/dnsmasq.d/" \ + -e ServerIP="${IP}" \ + # -e ServerIPv6="${IPv6}" \ + --restart=unless-stopped \ + --cap-add=NET_ADMIN \ + diginc/pi-hole:latest + +echo -n "Your password for https://${IP}/admin/ is " +docker logs pihole 2> /dev/null | grep 'password:' diff --git a/scripts/quickdb b/scripts/quickdb new file mode 100755 index 0000000..60c648f --- /dev/null +++ b/scripts/quickdb @@ -0,0 +1,6 @@ +#!/bin/bash + +docker run --rm -it \ + -e POSTGRES_PASSWORD=password -e POSTGRES_USER=evan -e POSTGRES_DB=evan \ + -p 5432:5432 \ + postgres:12.2 diff --git a/scripts/shuffle b/scripts/shuffle new file mode 100755 index 0000000..d255ac1 --- /dev/null +++ b/scripts/shuffle @@ -0,0 +1,8 @@ +#!/usr/bin/env python +import sys +import random + +lines = [line.strip() for line in sys.stdin.readlines()] +random.shuffle(lines) +for line in lines: + print(line) diff --git a/scripts/stopwatch b/scripts/stopwatch new file mode 100755 index 0000000..bf00e4f --- /dev/null +++ b/scripts/stopwatch @@ -0,0 +1,4 @@ +#!/bin/bash + +# stolen from https://stackoverflow.com/questions/37986523/how-can-i-create-a-stopwatch-in-bash +now=$(date +%s)sec; watch -n0.1 -p TZ=UTC date --date now-$now +%H:%M:%S.%N diff --git a/scripts/tfwrapper b/scripts/tfwrapper index 2dadf84..5ad8f2e 100755 --- a/scripts/tfwrapper +++ b/scripts/tfwrapper @@ -27,6 +27,9 @@ fi if [ -z "$TFWRAPPER_WORKING_DIR" ]; then terraform "$ARG1" "$@" +elif [ ! -d "$TFWRAPPER_WORKING_DIR" ]; then + echo -e "\033[31mInvalid directory $TFWRAPPER_WORKING_DIR\033" + exit 1 else ( cd $TFWRAPPER_WORKING_DIR diff --git a/scripts/timer b/scripts/timer new file mode 100755 index 0000000..f675fca --- /dev/null +++ b/scripts/timer @@ -0,0 +1,2 @@ +#!/bin/bash +now=$(date +%s)sec; watch -n0.1 -p TZ=UTC date --date now-$now +%H:%M:%S.%N diff --git a/scripts/today b/scripts/today new file mode 100755 index 0000000..2aa0177 --- /dev/null +++ b/scripts/today @@ -0,0 +1 @@ +date +%Y%m%d