From 3a6a1900031c181291adc4aead821994eb651cec Mon Sep 17 00:00:00 2001 From: Adam Lamers Date: Sun, 12 Nov 2023 02:10:49 -0500 Subject: [PATCH] new stuff --- bash_profile | 1 + common_shell_functions | 143 +++++++++++++++++++++++++++++++++-------- vimrc | 77 +++++++++++----------- zshrc | 19 ++++++ 4 files changed, 176 insertions(+), 64 deletions(-) diff --git a/bash_profile b/bash_profile index 9be1e90..920f887 100644 --- a/bash_profile +++ b/bash_profile @@ -58,3 +58,4 @@ _complete_ssh_hosts () complete -F _complete_ssh_hosts ssh complete -F _complete_ssh_hosts scp +. "$HOME/.cargo/env" diff --git a/common_shell_functions b/common_shell_functions index af98be8..7a8cc47 100644 --- a/common_shell_functions +++ b/common_shell_functions @@ -2,21 +2,39 @@ # This file is for shell functions common between shells: zsh, bash ################################################################### -function local_pi() { -LOCAL_PI_IP=$(en4ip) -ssh -b $LOCAL_PI_IP pi@169.254.100.100 +# Uses OSC52 to attempt to copy to client's clipboard through the terminal +function osc52() { + CB_DATA="$@" + echo -en "\033]52;c;$(echo $CB_DATA | base64)\a" +} + +function osc52_file() { + echo -en "\033]52;c;$(base64 $1)\a" } function pubkey() { - if [ -f ~/.ssh/id_rsa.pub ]; then + PUBKEY_PATH="$HOME/.ssh/id_rsa.pub" + SUCCESS=0 + if [ -f "$PUBKEY_PATH" ]; then if which pbcopy &> /dev/null; then - cat ~/.ssh/id_rsa.pub | pbcopy - echo "Copied public key using pbcopy" - else + cat $PUBKEY_PATH | pbcopy + SUCCESS=1 + echo "Copied public key [$PUBKEY_PATH] using pbcopy" + fi + + if [ "$SUCCESS" = "0" ]; then + osc52_file $PUBKEY_PATH + echo "Copied public key [$PUBKEY_PATH] using osc52" + SUCCESS=1 + fi + + if [ "$SUCCESS" = "0" ]; then echo "pbcopy not available - printing public key" echo - cat ~/.ssh/id_rsa.pub + cat $PUBKEY_PATH fi + else + echo "$PUBKEY_PATH does not exist" fi } @@ -58,25 +76,6 @@ function decrypt() { fi } -function init_flask() { - mkdir -p templates - touch templates/index.html - curl "https://raw.githubusercontent.com/lewagon/bootstrap-boilerplate/gh-pages/index.html" > templates/index.html - FLASK_TEMPLATE="from flask import Flask, render_template, request - -app = Flask(__name__) - -@app.route('/') -def index(): - return render_template('index.html') - -if __name__ == '__main__': - app.debug = True - app.run() -" - echo "$FLASK_TEMPLATE" > app.py -} - function weather() { LOCATION=milwaukee @@ -101,3 +100,93 @@ function flocate() { zgrep $1 /tmp/flocate.db --color=auto } +function install_pyenv() { + if [ ! -d "$HOME/.pyenv" ]; then + curl https://pyenv.run | bash + else + echo "pyenv is already installed" + echo "remove ~/.pyenv to reinstall" + fi + + echo "Installing python 3.9" + pyenv install 3.9 -s + + echo "Creating sandbox virtualenv" + pyenv virtualenv sandbox +} + +function install_nvm() { + if [ ! -f "$HOME/.nvm/nvm.sh" ]; then + PROFILE=/dev/null curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash + else + echo "nvm is already installed" + fi + nvm install --lts +} + +function install_rust() { + if [ ! -d "$HOME/.rustup" ]; then + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + else + echo "rustup is already installed. remove ~/.rustup to reinstall" + fi +} + +function init_apt() { + sudo apt-get install -y \ + libssl-dev \ + libncurses-dev \ + libbz2-dev \ + libffi-dev \ + libreadline-dev \ + libsqlite3-dev \ + liblzma-dev \ + python-is-python3 \ + python3-venv \ + build-essential \ + vim \ + tmux \ + net-tools \ + ripgrep \ +} + +function init_debian() { + init_apt + install_pyenv + install_nvm + install_rust +} + +function autosetup() { + if [ "$(uname)" = "Linux" ]; then + IS_LINUX="1" + else + IS_LINUX="0" + fi + + if [ "$IS_LINUX" = "1" ]; then + which lsb_release > /dev/null 2>&1 + if [ "$?" = "0" ]; then + DETECTED_DISTRO=$(lsb_release -a 2>/dev/null | grep Distributor | awk '{print $3}') + else + echo "Could not detect distribution" + fi + fi + + if [ "$IS_LINUX" = "1" ]; then + echo "Setting up Linux: $DETECTED_DISTRO" + + case $DETECTED_DISTRO in + Ubuntu*) + init_debian + ;; + Debian*) + init_debian + ;; + *) + echo "Unknown distribution $DETECTED_DISTRO" + ;; + esac + fi + unset IS_LINUX DETECTED_DISTRO +} diff --git a/vimrc b/vimrc index aa1aa27..cf85b4e 100644 --- a/vimrc +++ b/vimrc @@ -7,6 +7,24 @@ set nu set ignorecase filetype plugin indent on +"Space as leader +nmap +nnoremap +let mapleader="\" +let g:mapleader="\" + +"Buffer navigation +nnoremap [b :bp +nnoremap ]b :bn +nnoremap c :bd +nnoremap C :bd! +nnoremap f :echo expand('%:p') + +" Window navigation +nnoremap h +nnoremap j +nnoremap k +nnoremap l " Tab settings set expandtab @@ -23,18 +41,13 @@ autocmd FileType typescriptreact setlocal shiftwidth=2 tabstop=2 softtabstop=2 e autocmd FileType html setlocal shiftwidth=2 tabstop=2 softtabstop=2 expandtab autocmd FileType python setlocal shiftwidth=4 tabstop=4 softtabstop=4 expandtab - -"Space as leader -nmap -nnoremap -let mapleader="\" -let g:mapleader="\" - -" Window navigation -nnoremap h -nnoremap j -nnoremap k -nnoremap l +" Trim whitespace before write +fun! TrimWhitespace() + let l:save = winsaveview() + keeppatterns %s/\s\+$//e + call winrestview(l:save) +endfun +autocmd BufWritePre * call TrimWhitespace() set cmdheight=2 @@ -68,58 +81,48 @@ Plug 'peitalin/vim-jsx-typescript' Plug 'ojroques/vim-oscyank', {'branch': 'main'} call plug#end() - "Colorscheme colorscheme gruvbox-material +"Coc Config +function! ShowDocumentation() + if CocAction('hasProvider', 'hover') + call CocActionAsync('doHover') + else + call feedkeys('K', 'in') + endif +endfunction -"Coc Keybinds nmap d (coc-definition) nmap rn (coc-rename) -nmap gd (coc-definition) +nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) -imap (coc-snippets-expand) +imap (coc-snippets-expand) +inoremap coc#refresh() +inoremap coc#pum#visible() ? coc#pum#confirm() : +nnoremap K :call ShowDocumentation() let g:coc_disable_transparent_cursor=1 -"Use tab for snippet completion and jumping -inoremap - \ pumvisible() ? coc#_select_confirm() : - \ coc#expandableOrJumpable() ? "\=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\" : - \ check_back_space() ? "\" : - \ coc#refresh() - -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -let g:coc_snippet_next = '' - - "SimpylFold Config let g:SimpylFold_docstring_preview=1 - "NERDTree keybinds nmap g :NERDTreeFind nmap tt :NERDTreeFocus let NERDTreeIgnore = ['__pycache__', '\.pyc$', '\.egg-info$', 'node_modules'] - "CtrlP config nmap :CtrlPBuffer let g:ctrlp_working_path_mode= 0 let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git\|\.egg-info|\.pyc' - "fzf keybinds -let $FZF_DEFAULT_COMMAND = 'ag -g "" --ignore="(dist|*.svg)"' +let $FZF_DEFAULT_COMMAND = 'rg --files -g "!node_modules/"' nmap :FZF -nmap :Ag - +nmap :Rg "Wildignore set wildignore+=*/node_modules/*,*/__pycache__/*,*.pyc,*.egg-info diff --git a/zshrc b/zshrc index 57f483a..22017c5 100644 --- a/zshrc +++ b/zshrc @@ -81,3 +81,22 @@ fi if [ -f ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then . ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh fi + +#pyenv +if [ -f "$HOME/.pyenv/bin/pyenv" ]; then + export PYENV_ROOT="$HOME/.pyenv" + command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" + eval "$(pyenv init -)" +fi + +#nvm +if [ -f "$HOME/.nvm/nvm.sh" ]; then + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +fi + +#rust +if [ -f "$HOME/.cargo/env" ]; then + source "$HOME/.cargo/env" +fi