Improve OSX setup

This commit is contained in:
Lynda Wang 2020-07-25 19:39:09 -04:00 committed by Michael Campagnaro
parent ee11695dee
commit e2f40a7be7
27 changed files with 1378 additions and 702 deletions

View File

@ -39,7 +39,6 @@ abort() {
reload() {
if [[ $platform == 'Linux' || $platform == 'Darwin' ]]; then
#source ~/.zshrc
test -f ~/.aliases && . ~/.aliases
else
test -f ~/.aliases && . ~/.aliases
@ -445,6 +444,7 @@ alias pdot='cd ~/.private-dotfiles'
alias duh='du -csh'
alias exp='explorer .'
alias f='fg'
alias grep='grep -n --color '
alias history='fc -l 1'
alias histroy='history'
alias irb='irb --readline -r irb/completion'

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
source "$HOME/.dotfiles/script_helpers/all.sh"

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
source "$HOME/.dotfiles/script_helpers/printing.sh"
source "$HOME/.dotfiles/script_helpers/platform.sh"

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copies vim data from the home directory to the dotfiles repo.

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copies vim data from the dotfiles repo to the home directory.

68
install Normal file → Executable file
View File

@ -1,4 +1,15 @@
#!/bin/bash
#!/usr/bin/env bash
platform=`uname`
if [[ $platform == 'Darwin' ]]; then
if ! command -v brew &>/dev/null
then
# We need to update bash, so we'll start with setting up homebrew.
./osx/pre_install
exit
fi
fi
source "script_helpers/printing.sh"
source "script_helpers/core.sh"
@ -6,9 +17,10 @@ source "script_helpers/platform.sh"
source "script_helpers/file_ops.sh"
cwd=$PWD
platform=`uname`
confirm_link=0
os_is_windows is_windows
os_is_macos is_macos
os_is_linux is_linux
if [[ $is_windows -eq 1 ]]; then
# Check for admin permissions.
@ -26,32 +38,34 @@ set -e
####################################################################################################
setup_zsh() {
printf "Setting up zsh...\n"
printf "Setting up zsh...\n"
sudo apt install zsh
TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
if hash chsh >/dev/null 2>&1; then
printf "\n${BLUE}Changing the default shell to zsh${NORMAL}\n"
chsh -s $(grep /zsh$ /etc/shells | tail -1)
else
printf "\n${RED}Unable to change the shell because this system does not have chsh.\n"
printf "${BLUE}If this is Windows then you probably want to run the bash installer.${NORMAL}\n"
if [[ $is_linux -eq 1 ]]; then
sudo apt install zsh
fi
fi
FILES=()
FILES+=('zsh')
FILES+=('zshrc')
FILES+=('zshenv')
FILES+=('zlogin')
FILES+=('zprofile')
TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
if hash chsh >/dev/null 2>&1; then
printf "\n${BLUE}Changing the default shell to zsh${NORMAL}\n"
chsh -s $(grep /zsh$ /etc/shells | tail -1)
else
printf "\n${RED}Unable to change the shell because this system does not have chsh.\n"
printf "${BLUE}If this is Windows then you probably want to run the bash installer.${NORMAL}\n"
fi
fi
for file in "${FILES[@]}"
do
setup_file "$file"
done
setup_dir .dotfiles/zsh .zsh
FILES=()
FILES+=('zshrc')
FILES+=('zshenv')
FILES+=('zlogin')
for file in "${FILES[@]}"
do
setup_file .dotfiles/$file .$file
done
}
####################################################################################################
@ -96,9 +110,9 @@ if [[ $is_windows -eq 0 ]]; then
setup_zsh
fi
if [[ $platform == 'Darwin' ]]; then
printf "\n${BOLD}Running the OS X installer${NORMAL}\n"
./osx/install.sh
if [[ $is_macos -eq 1 ]]; then
printf "\n${BOLD}Running the MacOS installer${NORMAL}\n"
$cwd/osx/install
fi
popd "$HOME" &>/dev/null

75
osx/install Executable file
View File

@ -0,0 +1,75 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
set -e
printf "Installing env...\n"
ln -sf $HOME/.dotfiles/osx/env.platform $HOME/.env.platform
printf "Installing Git customizations...\n"
ln -sf $HOME/.dotfiles/osx/gitconfig.platform $HOME/.gitconfig.platform
#-----------------------------------
# Homebrew packages
#-----------------------------------
printf "Installing Homebrew...\n"
brew_packages=(
'openssl'
'wget'
'git'
'rlwrap'
'cmake'
'vim'
'sdl'
'tree'
)
brew tap homebrew/core
for package in "${brew_packages[@]}"
do
printf "Installing $package...\n"
ret=$(brew list | awk /$package/)
if [[ $ret == $package ]]; then
printf "${YELLOW}Already installed!${NORMAL}\n"
else
eval "brew install $package"
printf \n
fi
done
# We have issues downloading Rust on 10.11 with the patched Homebrew checkout
# so we'll install it using their script.
bash -c "$(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs)"
# For Vim search
cargo install ripgrep
# The homebrew core ctags package is very old.
brew install --HEAD universal-ctags/universal-ctags/universal-ctags
printf "\n${YELLOW}If you haven't already installed the Xcode dev tools then do so now by installing Xcode from the App Store:${NORMAL}\n"
printf "When that finishes open a terminal and run the following:\n"
printf " 1. ${YELLOW}sudo xcode-select --install${NORMAL}\n"
printf " 2. ${YELLOW}sudo xcodebuild -license${NORMAL}\n"
printf " 3. ${YELLOW}sudo xcode-select -s /Applications/Xcode.app/Contents/Developer${NORMAL}\n"
printf "\n${BOLD}Finished setting up OS X${NORMAL}\n"

View File

@ -1,52 +0,0 @@
#!/bin/bash
source "../script_helpers/printing.sh"
set -e
printf "Installing env...\n"
ln -sf $HOME/.dotfiles/osx/env.platform $HOME/.env.platform
printf "Installing git customizations...\n"
ln -sf $HOME/.dotfiles/osx/gitconfig.platform $HOME/.gitconfig.platform
brew tap homebrew/core
printf "Installing xquartz..."
#brew cask install xquartz
brew_packages=(
'tree'
'openssl'
'git'
# 'xclip'
'rlwrap'
'cmake'
'pkg-config'
'vim'
'the_silver_searcher'
'selecta'
# 'rust'
# 'go'
'sdl')
for package in "${brew_packages[@]}"
do
printf "Installing $package..."
ret=$(brew list | awk /$package/)
if [[ $ret == $package ]]; then
printf "${YELLOW}already installed!${NORMAL}\n"
else
eval "brew install $package"
printf \n
fi
done
printf "\n${YELLOW}Now you must install Xcode.${NORMAL}\n"
printf "Open the App Store and install the software.\n"
printf "When that finishes open a terminal and run the following:\n"
printf " 1. ${YELLOW}sudo xcode-select --install${NORMAL}\n"
printf " 2. ${YELLOW}sudo xcodebuild -license${NORMAL}\n"
printf " 3. ${YELLOW}sudo xcode-select -s /Applications/Xcode.app/Contents/Developer${NORMAL}\n"
printf "\n${BOLD}Finished setting up OS X${NORMAL}\n"

54
osx/pre_install Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
set -e
printf "Installing Homebrew...\n"
# OSX 10.11 and earlier will issue certificate errors when Homebrew attempts to download packages
# with curl. Detect if we're running on 10.11 or earlier and if so use a fork that passes the
# --insecure option to curl.
kernel_major="$(uname -r | sed 's/\..*//')"
case $kernel_major in
15 | 14 | 13) download_patched_homebrew=1 ;;
*) download_patched_homebrew=0 ;;
esac
if [[ $download_patched_homebrew -eq 1 ]]; then
printf "${BOLD}Current MacOS kernel ${NORMAL}${YELLOW}$(uname -r)${NORMAL}${BOLD} requires a patched version of Homebrew...${NORMAL}\n"
bash -c "$(curl -fsSL https://raw.githubusercontent.com/sir-pinecone/brew/master/install.sh)"
else
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
fi
brew tap homebrew/core
printf "\nInstalling bash...\n"
ret=$(brew list | awk /$package/)
if [[ $ret == $package ]]; then
printf "${YELLOW}Already installed!${NORMAL}\n"
else
eval "brew install bash"
printf "\n${YELLOW}Finished installing updated version of bash.\nYou must now enable it. Run:${NORMAL}\n"
printf " ${BOLD}sudo vim /etc/shells${NORMAL}\n"
printf "${YELLOW}And add ${NORMAL}${BOLD}/usr/local/bin/bash${NORMAL}${YELLOW} to the end of the list. After that close your terminal and re-run the dotfiles install script.${NORMAL}\n"
fi

View File

@ -1,14 +0,0 @@
# OSX
## Setting up Ruby
* Install rvm
* Install bundler
* Install Ruby Docs
gem install rdoc-data
rdoc-data --install
gem rdoc --all --overwrite
## Setup Keyboard
Map <CapsLock> to <Ctrl> in System Preferences -> Keyboard -> Modifier Keys. Now <caps-c> can leave insert mode.

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
source_helpers="$HOME/.dotfiles/script_helpers"
source "$source_helpers/printing.sh"

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#---------------------------------------------------------------------------------------------------
# API

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Requires the printing.sh helper to be sourced.

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Requires the printing.sh helper to be sourced.
# Requires the platform.sh helper to be sourced.
@ -165,12 +165,14 @@ link_file() {
echo "expand_symlinks? $expand_symlinks"
fi
if [[ $expand_symlinks -eq 1 ]]; then
source_path=$(expand_path "$source_path")
dest_path=$(expand_path "$dest_path")
else
source_path=$(_clean_link_file_path "$source_path")
dest_path=$(_clean_link_file_path "$dest_path")
if [[ $is_windows -eq 1 ]]; then
if [[ $expand_symlinks -eq 1 ]]; then
source_path=$(expand_path "$source_path")
dest_path=$(expand_path "$dest_path")
else
source_path=$(_clean_link_file_path "$source_path")
dest_path=$(_clean_link_file_path "$dest_path")
fi
fi
if [[ $debug -eq 1 ]]; then
@ -210,6 +212,7 @@ link_file() {
echo Link cmd:: $link_cmd
fi
printf "${BOLD}*${NORMAL} ${YELLOW}Linking '$source_path'${NORMAL} to ${YELLOW}'$dest_path'${NORMAL}\n"
eval $link_cmd
}

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#---------------------------------------------------------------------------------------------------
# API

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
uname_s="$(uname -s)"
case "${uname_s}" in

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)

346
vimrc
View File

@ -134,11 +134,6 @@ Plug 'nelstrom/vim-qargs' " For the GlobalReplaceIt function (i.e. s
if IsWindows()
Plug 'suxpert/vimcaps' " Disable capslock (useful if the OS isn't configured to do so).
else
" Fuzzy search
" @incomplete Test out ctrlp for non-Windows setup.
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Plug 'junegunn/fzf.vim'
" @fixme Doesn't do anything under Windows...
" Plug 'ervandew/supertab' " Improved autocompletion.
endif
@ -332,75 +327,75 @@ imap <right> <nop>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup campoCmds
" Clear all autocmds in the group.
autocmd!
" Clear all autocmds in the group.
autocmd!
" Automatically wrap at N characters.
autocmd FileType gitcommit setlocal colorcolumn=72
autocmd BufRead,BufNewFile *.{md,txt,plan} execute "setlocal textwidth=" .s:max_line_length
" Automatically wrap at N characters.
autocmd FileType gitcommit setlocal colorcolumn=72
autocmd BufRead,BufNewFile *.{md,txt,plan} execute "setlocal textwidth=" .s:max_line_length
" Spell checking.
autocmd FileType gitcommit,markdown,text setlocal spell
" Spell checking.
autocmd FileType gitcommit,markdown,text setlocal spell
" Jump to last cursor position unless it's invalid or in an event handler.
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" Jump to last cursor position unless it's invalid or in an event handler.
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" Indent HTML <p> tags.
autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
" Indent HTML <p> tags.
autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
" Properly indent schemes (scheme, racket, etc).
autocmd bufread,bufnewfile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt
" Properly indent schemes (scheme, racket, etc).
autocmd bufread,bufnewfile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt
" Auto reload VIM when settings changed.
autocmd BufWritePost .vimrc so $MYVIMRC
autocmd BufWritePost *.vim so $MYVIMRC
autocmd BufWritePost ~/.vimrc.private so $MYVIMRC
" Auto reload VIM when settings changed.
autocmd BufWritePost .vimrc so $MYVIMRC
autocmd BufWritePost *.vim so $MYVIMRC
autocmd BufWritePost ~/.vimrc.private so $MYVIMRC
function! s:RunCtags()
" The ampersand at the end is to make this run in the background. I had to
" group the commands in parens to make the chained commands run in the
" background.
let l:ctags_cmd = "!(ctags --c-types=+l --c++-types=+l --exclude=*.md --exclude=*.txt --exclude=*.config --exclude=*.css --exclude=*.html --exclude=*.htm --exclude=*.json --exclude=node_modules --exclude=.git --exclude=.cache " . g:campo_custom_ctags_args . " -R -o newtags; mv newtags tags) &"
exec l:ctags_cmd | redraw!
endfun
" Generate ctags on save.
" Also Include local variables for C-like languages.
autocmd BufWritePost *.cs,*.js,*.py,*.c,*.cpp,*.h silent! :call <SID>RunCtags()
function! s:RunCtags()
" The ampersand at the end is to make this run in the background. I had to
" group the commands in parens to make the chained commands run in the
" background.
let l:ctags_cmd = "!(ctags --c-types=+l --c++-types=+l --exclude=*.md --exclude=*.txt --exclude=*.config --exclude=*.css --exclude=*.html --exclude=*.htm --exclude=*.json --exclude=node_modules --exclude=.git --exclude=.cache " . g:campo_custom_ctags_args . " -R -o newtags; mv newtags tags) &"
exec l:ctags_cmd | redraw!
endfun
" Generate ctags on save.
" Also Include local variables for C-like languages.
autocmd BufWritePost *.cs,*.js,*.py,*.c,*.cpp,*.h silent! :call <SID>RunCtags()
" Remove trailing whitespace when saving any file.
function! s:StripTrailingWhitespaces()
if g:campo_strip_trailing_whitespace
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endif
endfun
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
" Remove trailing whitespace when saving any file.
function! s:StripTrailingWhitespaces()
if g:campo_strip_trailing_whitespace
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endif
endfun
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
"////////////////////////////////////////////////////////////////
" FILE TEMPLATES
"////////////////////////////////////////////////////////////////
"////////////////////////////////////////////////////////////////
" FILE TEMPLATES
"////////////////////////////////////////////////////////////////
" Shell script template.
autocmd BufNewFile *.sh 0r ~/.vim/templates/skeleton.sh
autocmd BufNewFile *.plan 0r ~/.vim/templates/skeleton.plan
" Shell script template.
autocmd BufNewFile *.sh 0r ~/.vim/templates/skeleton.sh
autocmd BufNewFile *.plan 0r ~/.vim/templates/skeleton.plan
" C/C++ template.
autocmd bufnewfile *.{c,cc,cpp,h,hpp} 0r ~/.vim/templates/c_header_notice
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/File:.*/s//File: " .expand("%")
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/Creation Date:.*/s//Creation Date: " .strftime("%Y-%m-%d")
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/$year/s//" .strftime("%Y")
function! s:InsertHeaderGates()
let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g")
execute "normal! ggO#ifndef " . gatename
normal! Go
normal! Go
execute "normal! Go#define " . gatename . " "
execute "normal! o#endif"
normal! kkk
endfunction
autocmd bufnewfile *.{h,hpp} call <SID>InsertHeaderGates()
" C/C++ template.
autocmd bufnewfile *.{c,cc,cpp,h,hpp} 0r ~/.vim/templates/c_header_notice
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/File:.*/s//File: " .expand("%")
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/Creation Date:.*/s//Creation Date: " .strftime("%Y-%m-%d")
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/$year/s//" .strftime("%Y")
function! s:InsertHeaderGates()
let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g")
execute "normal! ggO#ifndef " . gatename
normal! Go
normal! Go
execute "normal! Go#define " . gatename . " "
execute "normal! o#endif"
normal! kkk
endfunction
autocmd bufnewfile *.{h,hpp} call <SID>InsertHeaderGates()
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ -446,16 +441,16 @@ map Q <Nop>
" Open a terminal within vim. Use `exit` to close it.
if exists(':terminal')
map <leader>t :terminal<cr>
tnoremap <leader>e <C-\><C-n>
tnoremap <A-h> <C-\><C-n><C-w>h
tnoremap <A-j> <C-\><C-n><C-w>j
tnoremap <A-k> <C-\><C-n><C-w>k
tnoremap <A-l> <C-\><C-n><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
map <leader>t :terminal<cr>
tnoremap <leader>e <C-\><C-n>
tnoremap <A-h> <C-\><C-n><C-w>h
tnoremap <A-j> <C-\><C-n><C-w>j
tnoremap <A-k> <C-\><C-n><C-w>k
tnoremap <A-l> <C-\><C-n><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
endif
" Jump to other buffers.
@ -493,7 +488,7 @@ map <leader>= z=
" Clear the search buffer (highlighting) when hitting return.
function! MapCR()
nnoremap <cr> :nohlsearch<cr>
nnoremap <cr> :nohlsearch<cr>
endfunction
call MapCR()
nnoremap <leader><leader> <c-^>
@ -514,10 +509,10 @@ nnoremap <c-g> :%s///g<left><left>
"////////////////////////////////////////////////////////////////
function! s:CompleteFilenameWithoutExtension(ArgLead, CmdLine, CursorPos)
" Returns a matching filename without the period that separates the name
" from the extension.
let l:file = substitute(glob(a:ArgLead.'*', 0, 0), "[\.].*", "", "*")
return l:file
" Returns a matching filename without the period that separates the name
" from the extension.
let l:file = substitute(glob(a:ArgLead.'*', 0, 0), "[\.].*", "", "*")
return l:file
endfunction
" Custom command to open cpp and h files without typing an extension
@ -681,9 +676,9 @@ let s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gr
let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray']
function! UpdateRainbowConf()
let g:rainbow_conf = {
let g:rainbow_conf = {
\ 'ctermfgs': (s:rainbow_theme == "light"? s:dark_rainbow : s:light_rainbow)
\}
\}
"\ 'separately': {
"\ '*': 0, " Disable all
"\ 'c++': {} " Only enable c++
@ -693,18 +688,18 @@ endfunction
call UpdateRainbowConf()
function! ReloadRainbow()
if g:campo_theme_use_rainbow_parens
if exists(':RainbowToggle')
call UpdateRainbowConf()
call rainbow#clear() | call rainbow#hook()
if g:campo_theme_use_rainbow_parens
if exists(':RainbowToggle')
call UpdateRainbowConf()
call rainbow#clear() | call rainbow#hook()
endif
else
let g:rainbow_active = 0
if exists(':RainbowToggle')
call UpdateRainbowConf()
call rainbow#clear()
endif
endif
else
let g:rainbow_active = 0
if exists(':RainbowToggle')
call UpdateRainbowConf()
call rainbow#clear()
endif
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ -731,19 +726,19 @@ set tags+=tags;$HOME
" CENTER THE BUFFER
"////////////////////////////////////////////////////////////////
function! CenterPane()
" centers the current pane as the middle 2 of 4 imaginary columns
" should be called in a window with a single pane
" Taken from https://dev.to/vinneycavallo/easily-center-content-in-vim
lefta vnew
wincmd w
exec 'vertical resize '. string(&columns * 0.75)
endfunction
function! CenterPane()
" centers the current pane as the middle 2 of 4 imaginary columns
" should be called in a window with a single pane
" Taken from https://dev.to/vinneycavallo/easily-center-content-in-vim
lefta vnew
wincmd w
exec 'vertical resize '. string(&columns * 0.75)
endfunction
nnoremap <leader>c :call CenterPane()<cr>
function! RemoveCenterPane()
wincmd w
close
wincmd w
close
endfunction
nnoremap <leader>cw :call RemoveCenterPane()<cr>
@ -772,24 +767,24 @@ map <leader>l :call ChangeBgTheme('light', 0)<cr>
map <leader>ll :call ChangeBgTheme('dark', 0)<cr>
function! ChangeBgTheme(bg, onlySetTheme)
if a:bg =~ 'light'
let s:rainbow_theme = 'light'
let s:theme = g:campo_light_theme
exe 'colorscheme ' . s:theme
set background=light
else
let s:rainbow_theme = 'dark'
let s:theme = g:campo_dark_theme
" We have to set the theme twice in order to get its correct dark-theme colors.
" Weird stuff.
exe 'colorscheme ' . s:theme
set background=dark
exe 'colorscheme ' . s:theme
endif
if a:bg =~ 'light'
let s:rainbow_theme = 'light'
let s:theme = g:campo_light_theme
exe 'colorscheme ' . s:theme
set background=light
else
let s:rainbow_theme = 'dark'
let s:theme = g:campo_dark_theme
" We have to set the theme twice in order to get its correct dark-theme colors.
" Weird stuff.
exe 'colorscheme ' . s:theme
set background=dark
exe 'colorscheme ' . s:theme
endif
if !a:onlySetTheme
exec ':AirlineTheme ' . a:bg
endif
if !a:onlySetTheme
exec ':AirlineTheme ' . a:bg
endif
endfunction
if s:default_bg =~ 'light'
@ -878,35 +873,35 @@ set errorformat+=\\\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m
set errorformat+=\\\ %#%f(%l\\\,%c-%*[0-9]):\ %#%t%[A-z]%#\ %m
function! HideBuildResultsAndClearErrors()
RemoveErrorMarkers
call asyncrun#quickfix_toggle(g:quickfix_window_height, 0)
RemoveErrorMarkers
call asyncrun#quickfix_toggle(g:quickfix_window_height, 0)
endfunction
function! HideAsyncResults()
call asyncrun#quickfix_toggle(g:quickfix_window_height, 0)
call asyncrun#quickfix_toggle(g:quickfix_window_height, 0)
endfunction
function! ToggleBuildResults()
call asyncrun#quickfix_toggle(g:quickfix_window_height)
call asyncrun#quickfix_toggle(g:quickfix_window_height)
endfunction
function! StopRunTask()
AsyncStop
call HideAsyncResults()
AsyncStop
call HideAsyncResults()
endfunction
function! ExecuteRunScript()
exec "AsyncRun! -post=call\\ StopRunTask() ./run %"
exec "AsyncRun! -post=call\\ StopRunTask() ./run %"
endfunction
function! SilentBuild()
AsyncStop
exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() ./build* %"
AsyncStop
exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() ./build* %"
endfunction
" Show results window the moment the async job starts
augroup vimrc
autocmd User AsyncRunStart call asyncrun#quickfix_toggle(g:quickfix_window_height, 1)
autocmd User AsyncRunStart call asyncrun#quickfix_toggle(g:quickfix_window_height, 1)
augroup END
" Toggle build results
@ -939,35 +934,23 @@ nnoremap <C-p> :cp<CR>
" SEARCH
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" @incomplete
if !IsWindows()
let rg_args = "--column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --pretty \"always\" " . g:campo_custom_search_args
let cmd = "command! -bang -nargs=* Find call fzf#vim#grep('rg " . rg_args . "'.shellescape(<q-args>), 1, <bang>0)"
exec cmd
endif
" Search using ripgrep (first install with Rust: cargo install ripgrep).
function! Search(case_sensitive)
let helper = "[" . (a:case_sensitive ? "case-sensitive" : "case-insensitive") . "] search: "
let term = input(helper)
if empty(term)
return
endif
let l:helper = "[" . (a:case_sensitive ? "case-sensitive" : "case-insensitive") . "] search: "
let l:term = input(l:helper)
if empty(l:term)
return
endif
"@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the
"quickfix window doesn't seem to parse the ansi color codes.
let rg_args = "--trim -g \"!tags\" " . g:campo_custom_search_args
"@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the
"quickfix window doesn't seem to parse the ansi color codes.
let l:rg_args = "--column --line-number --no-heading --fixed-strings --no-ignore --hidden --follow --trim -g \"!tags\" " . g:campo_custom_search_args
if !a:case_sensitive
let rg_args .= " --ignore-case"
endif
if !a:case_sensitive
let l:rg_args .= " --ignore-case"
endif
if IsWindows()
exec 'Rg ' . rg_args . ' "' . term . '"'
else
" @incomplete Test out ripgrep on non-Windows OS
echo "Not implemented"
endif
exec 'Rg ' . l:rg_args . ' "' . l:term . '"'
endfunction
map <leader>s :call Search(0)<cr>
map <leader>ss :call Search(1)<cr>
@ -978,45 +961,44 @@ map <leader>ss :call Search(1)<cr>
nnoremap <expr> o (&buftype is# "quickfix" ? "<CR>\|:lopen<CR>" : "o")
nnoremap <expr> p (&buftype is# "quickfix" ? "<CR>\|:copen<CR>" : "p")
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SEARCH & REPLACE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Replace the selected text in all files within the repo.
function! GlobalReplaceIt(confirm_replacement)
if exists(':Ggrep')
call inputsave()
if exists(':Ggrep')
call inputsave()
if a:confirm_replacement
let l:term = input('Enter search term (w/ confirmation): ')
if a:confirm_replacement
let l:term = input('Enter search term (w/ confirmation): ')
else
let l:term = input('Enter search term (no confirmation): ')
endif
call inputrestore()
if empty(l:term)
return
endif
call inputsave()
let l:replacement = input('Enter replacement: ')
call inputrestore()
if empty(l:replacement)
return
endif
if a:confirm_replacement
let l:confirm_opt = 'c'
else
let l:confirm_opt = 'e'
endif
execute 'Ggrep '.l:term
execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt.' | update'
else
let l:term = input('Enter search term (no confirmation): ')
echo "Unable to search since you're not in a git repo"
endif
call inputrestore()
if empty(l:term)
return
endif
call inputsave()
let l:replacement = input('Enter replacement: ')
call inputrestore()
if empty(l:replacement)
return
endif
if a:confirm_replacement
let l:confirm_opt = 'c'
else
let l:confirm_opt = 'e'
endif
execute 'Ggrep '.l:term
execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt.' | update'
else
echo "Unable to search since you're not in a git repo"
endif
endfunction
map <leader>r :call GlobalReplaceIt(0)<cr>
map <leader>rr :call GlobalReplaceIt(1)<cr>

View File

@ -159,7 +159,7 @@ processor time and is generally useless.
### Setting up Custom Search
* First install Rusto. See `Setting up Rust` below.
* First install Rust. See `Setting up Rust` below.
* Setup `ripgrep`:
* Open an `msvc x64` shell and run `cargo install ripgrep`. **Note** the last time I did this
I got linker errors saying that it was trying to link an x86 exe in a 64-bit env. I had to run

18
zlogin
View File

@ -1,11 +1,7 @@
# go to saved path if there is one
if [[ -f ~/.current_path~ ]]; then
cd `cat ~/.current_path~`
rm ~/.current_path~
fi
# Need to edit the path again here so that we can get the homebrew bin folder ahead of
# everything else. This is necessary because zsh is modifying the path in zshrc, and
# that causes us to run out of /usr/bin for programs that we want to use from homebrew's
# bin
path=($HOME/homebrew/opt/openssl/bin $HOME/homebrew/sbin $HOME/homebrew/bin $path)
# Need to edit the path again here so that we can get the homebrew bin folder
# ahead of everything else. This is necessary because zsh is modifying the path
# in zshrc, and that causes us to run out of /usr/bin for programs that we want
# to use from homebrew's bin
#
# Update 2020-07-25: This no longer seems to be an issue.
#path=(/usr/local/bin /usr/local/sbin /usr/local/opt/openssl/bin $path)

View File

@ -1 +0,0 @@
source ~/.zshrc

21
zshenv
View File

@ -1,10 +1,4 @@
platform=`uname -s`
kernel_release=`uname -r`
test -f ~/.aliases.private && . ~/.aliases.private
# Common env must come first.
test -f ~/.private-dotfiles.common/env && . ~/.private-dotfiles.common/env
test -f ~/.private-dotfiles/env && . ~/.private-dotfiles/env
# Unbreak broken, non-colored terminal
export TERM=xterm-256color
@ -17,11 +11,10 @@ export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_INSECURE_REDIRECT=1
export HOMEBREW_CASK_OPTS=--require-sha
# Grep tweaks
export GREP_OPTIONS="-nRi --color --exclude-dir=.git --exclude-dir=tmp --exclude-dir=log --exclude-dir=node_modules --exclude-dir=bower_components --exclude-dir=coverage --exclude-dir=.bundle --exclude=*.csv --exclude=*.pdf --exclude-dir=vendor --exclude-dir=rdoc --exclude-dir=target --exclude-dir=personal --exclude-dir=resources/public/js/*.*" # --exclude-dir=images --exclude-dir=coverage
# Ruby
export RBENV_PATH="$HOME/.rbenv"
# Clojure
export LEIN_FAST_TRAMPOLINE=y
if [[ $platform == 'Linux' ]]; then
@ -32,16 +25,6 @@ if [[ $platform == 'Linux' ]]; then
export LOLCOMMITS_DIR="/shared/Dev/lolcommits"
fi
path=($HOME/bin $HOME/.dotfiles/bin ${RBENV_PATH}/bin $HOME/.vim/scripts $path)
if [[ $platform == 'Darwin' ]]; then
test -f $HOME/.cargo && source $HOME/.cargo/env
# TODO: test for qt
if [ -d "$HOME/Qt" ]; then
path=($HOME/Qt/5.8/clang_64/bin $path)
fi
fi
if [ -d "$HOME/.rbenv" ]; then
# Start rbenv
eval "$(rbenv init -)"

15
zshrc
View File

@ -90,8 +90,19 @@ bindkey -e
source $ZSH/lib/*.zsh
# Source my custom files after oh-my-zsh so I can override things.
source $HOME/.env.platform
source $HOME/.aliases
test -f $HOME/.aliases && . $HOME/.aliases
test -f $HOME/.aliases.private && . $HOME/.aliases.private
# Common env must come first.
test -f $HOME/.private-dotfiles.common/env && . $HOME/.private-dotfiles.common/env
test -f $HOME/.private-dotfiles/env && . $HOME/.private-dotfiles/env
if [[ -d "$HOME/bin" ]]; then
export PATH=$HOME/bin/:$PATH
fi
if [[ -d "$HOME/.dotfiles/bin" ]]; then
export PATH=$HOME/.dotfiles/bin/:$PATH
fi
# Fix <c-h> in neovim
infocmp $TERM | sed 's/kbs=^[hH]/kbs=\\177/' > $HOME/.$TERM.ti