Last active
October 19, 2021 01:48
-
-
Save adamazing/9419e408df423e7148012daa966e91ce to your computer and use it in GitHub Desktop.
My Config Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible | |
nnoremap <C-h> <C-w>h | |
nnoremap <C-j> <C-w>j | |
nnoremap <C-k> <C-w>k | |
nnoremap <C-l> <C-w>l | |
if !exists('g:vscode') | |
"---- vim-plug setup ---- | |
let vimplug_exists=expand('~/.config/nvim/autoload/plug.vim') | |
if has('win32')&&!has('win64') | |
let curl_exists=expand('C:\Windows\Sysnative\curl.exe') | |
else | |
let curl_exists=expand('curl') | |
endif | |
if !filereadable(vimplug_exists) | |
if !executable(curl_exists) | |
echoerr "You have to install curl or first install vim-plug yourself!" | |
execute "q!" | |
endif | |
echo "Installing Vim-Plug..." | |
echo "" | |
silent exec "!"curl_exists" -fLo " . shellescape(vimplug_exists) . " --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" | |
let g:not_finish_vimplug = "yes" | |
autocmd VimEnter * PlugInstall | |
endif | |
"-------- end vim-plug setup ---- | |
syntax enable | |
filetype plugin indent on | |
set nu | |
set rnu | |
set completeopt=menuone,noinsert,noselect | |
set shortmess+=c | |
set smartindent | |
set cmdheight=2 | |
set updatetime=50 | |
set signcolumn=yes | |
set virtualedit=block | |
set encoding=UTF-8 | |
set noswapfile | |
set expandtab | |
set tabstop=2 softtabstop=0 shiftwidth=2 smarttab | |
set hlsearch | |
set ignorecase | |
set incsearch | |
set colorcolumn=150 | |
set mouse=nv | |
" set guifont=CaskaydiaCove\ Nerd\ Font\ Mono | |
set noshowmode | |
" set guifont=FiraCode\ Nerd\ Font\ Mono:h14 | |
call plug#begin('~/.config/nvim/plugged') | |
" Sensible default | |
Plug 'tpope/vim-sensible' | |
Plug 'tpope/vim-speeddating' | |
Plug 'tpope/vim-abolish' | |
Plug 'tpope/vim-rails' | |
Plug 'tpope/vim-surround' | |
Plug 'tpope/vim-fugitive' | |
Plug 'tpope/vim-commentary' | |
Plug 'tpope/vim-endwise' | |
" Color schemes | |
" Plug 'sainnhe/edge' | |
" Plug 'junegunn/seoul256.vim' | |
Plug 'morhetz/gruvbox' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'hoob3rt/lualine.nvim' | |
Plug 'kyazdani42/nvim-web-devicons' | |
Plug 'kyazdani42/nvim-tree.lua' | |
Plug 'folke/trouble.nvim' | |
Plug 'folke/lsp-colors.nvim' | |
Plug 'tpope/vim-unimpaired' | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'kabouzeid/nvim-lspinstall' | |
Plug 'hrsh7th/vim-vsnip' | |
Plug 'hrsh7th/nvim-compe' | |
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} | |
Plug 'nvim-lua/popup.nvim' | |
Plug 'nvim-lua/plenary.nvim' | |
Plug 'nvim-telescope/telescope.nvim' | |
Plug 'jiangmiao/auto-pairs' | |
Plug 'frazrepo/vim-rainbow' | |
call plug#end() | |
highlight ColorColumn ctermbg=grey guibg=grey | |
augroup vimrc_autocmds | |
autocmd InsertLeave * highlight OverLength ctermbg=red guibg=red | |
autocmd InsertLeave * match OverLength /\%150v.*/ | |
augroup END | |
if has('termguicolors') | |
set termguicolors | |
endif | |
" let g:edge_style = 'aura' | |
" let g:edge_enable_italic = 1 | |
" let g:edge_disable_italic_comment = 1 | |
" colorscheme edge | |
" Unified color scheme (default: dark) | |
" let g:seoul256_background=234 | |
let g:gruvbox_contrast_light='hard' | |
let g:gruvbox_contrast_dark='soft' | |
colo gruvbox | |
function ToggleDarkLightMode() | |
let &bg=(&bg=='light'?'dark':'light') | |
endfunction | |
nnoremap <leader>bg :let &bg=(&bg=='light'?'dark':'light')<CR> | |
let g:neovide_cursor_vfx_mode = "railgun" | |
let g:neovide_cursor_antialiasing=v:true | |
let g:nvim_tree_auto_open = 1 | |
let g:nvim_tree_auto_close = 1 "0 by default, closes the tree when it's the last window | |
let g:nvim_tree_special_files = [ 'README.md', 'Makefile', 'MAKEFILE' ] " List of filenames that gets highlighted with NvimTreeSpecialFile | |
let g:nvim_tree_show_icons = { | |
\ 'git': 1, | |
\ 'folders': 1, | |
\ 'files': 1, | |
\ } | |
let g:nvim_tree_lsp_diagnostics = 1 | |
let g:nvim_tree_width_allow_resize = 1 | |
let g:nvim_tree_hide_dotfiles = 1 "0 by default, this option hides files and folders starting with a dot `.` | |
nnoremap <leader>t :NvimTreeToggle<CR> | |
nnoremap <C-bslash> :NvimTreeFindFile<CR> | |
nnoremap <Leader>fp :let @+=expand('%:p')<CR> | |
let g:rainbow_active=1 | |
let g:ruby_host_prog='~/.rbenv/shims/neovim-ruby-host' | |
" function which trims trailing whitespace | |
fun! TrimWhitespace() | |
let l:save = winsaveview() | |
keeppattern %s/\s\+$//e | |
call winrestview(l:save) | |
endfun | |
augroup AJH | |
autocmd! | |
autocmd BufWritePre * :call TrimWhitespace() | |
augroup END | |
" :Fix searches and replaces all but the first instance of 'pick' to 'f' to squash previous commits into a fix commit | |
function! Fix() | |
:2,$s/^pick /f / | |
:wq | |
endfunction | |
" Abbreviate the Fix() call so it can be run with `ff` | |
cabbrev ff call Fix() | |
augroup highlight_yank | |
autocmd! | |
autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank() | |
augroup END | |
inoremap ;; <Esc> | |
vnoremap ;; <Esc> | |
nnoremap <leader>] :vertical resize +5<CR> | |
nnoremap <leader>[ :vertical resize -5<CR> | |
nnoremap <leader>= :res +5<CR> | |
nnoremap <leader>- :res -5<CR> | |
nnoremap <silent> <leader> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><leader>l | |
" inoremap <silent><expr> <C-Space> <cmd>compe#complete() | |
" inoremap <silent><expr> <CR> <cmd>compe#confirm('<CR>') | |
" inoremap <silent><expr> <C-e> <cmd>compe#close('<C-e>') | |
" Trouble Keymappings | |
nnoremap <leader>xx <cmd>TroubleToggle<cr> | |
nnoremap <leader>xw <cmd>TroubleToggle lsp_workspace_diagnostics<cr> | |
nnoremap <leader>xd <cmd>TroubleToggle lsp_document_diagnostics<cr> | |
nnoremap <leader>xq <cmd>TroubleToggle quickfix<cr> | |
nnoremap <leader>xl <cmd>TroubleToggle loclist<cr> | |
nnoremap <silent>gr <cmd>TroubleToggle lsp_references<cr> | |
" Find files using Telescope command-line sugar. | |
nnoremap <leader>ff <cmd>Telescope find_files<cr> | |
nnoremap <leader>fg <cmd>Telescope live_grep<cr> | |
nnoremap <leader>fb <cmd>Telescope buffers<cr> | |
nnoremap <leader>fh <cmd>Telescope help_tags<cr> | |
" LSP config (the mappings used in the default file don't quite work right) | |
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR> | |
nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR> | |
" nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR> | |
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR> | |
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR> | |
nnoremap <leader>k <cmd>lua vim.lsp.buf.signature_help()<CR> | |
nnoremap <silent> <C-n> <cmd>lua vim.lsp.diagnostic.goto_prev()<CR> | |
nnoremap <silent> <C-p> <cmd>lua vim.lsp.diagnostic.goto_next()<CR> | |
" ---------------- ---- -- LSP --- --- -- -- - | |
:lua << EOF | |
local nvim_lsp = require('lspconfig') | |
local on_attach = function(client, bufnr) | |
require('completion').on_attach() | |
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end | |
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end | |
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | |
-- Mappings | |
local opts = { noremap=true, silent=true } | |
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | |
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | |
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | |
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | |
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | |
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) | |
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) | |
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | |
-- Set some keybinds conditional on server capabilities | |
if client.resolved_capabilities.document_formatting then | |
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | |
elseif client.resolved_capabilities.document_range_formatting then | |
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | |
end | |
-- Set autocommands conditional on server_capabilities | |
if client.resolved_capabilities.document_highlight then | |
require('lspconfig').util.nvim_multiline_command [[ | |
:hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow | |
:hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow | |
:hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow | |
augroup lsp_document_highlight | |
autocmd! | |
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() | |
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() | |
augroup END | |
]] | |
end | |
end | |
local function setup_servers() | |
require'lspinstall'.setup() | |
local servers = require'lspinstall'.installed_servers() | |
for _, server in pairs(servers) do | |
-- print(server) | |
nvim_lsp[server].setup{} | |
-- require'lspconfig'[server].setup{} | |
end | |
end | |
require'compe'.setup { | |
enabled = true; | |
autocomplete = true; | |
debug = false; | |
min_length = 1; | |
preselect = 'enable'; | |
throttle_time = 80; | |
source_timeout = 200; | |
incomplete_delay = 400; | |
max_abbr_width = 100; | |
max_kind_width = 100; | |
max_menu_width = 100; | |
documentation = true; | |
source = { | |
path = true; | |
buffer = true; | |
calc = true; | |
nvim_lsp = true; | |
nvim_lua = true; | |
vsnip = true; | |
}; | |
} | |
local function setup_status_line() | |
require'lualine'.setup { | |
options = { | |
icons_enabled = true, | |
theme = 'gruvbox', | |
component_separators = {'', ''}, | |
section_separators = {'', ''}, | |
disabled_filetypes = {} | |
}, | |
sections = { | |
lualine_a = {'mode'}, | |
lualine_b = {'branch'}, | |
lualine_c = {'filename'}, | |
lualine_x = {'encoding', 'fileformat', 'filetype'}, | |
lualine_y = {'progress'}, | |
lualine_z = {'location'} | |
}, | |
inactive_sections = { | |
lualine_a = {}, | |
lualine_b = {}, | |
lualine_c = {'filename'}, | |
lualine_x = {'location'}, | |
lualine_y = {}, | |
lualine_z = {} | |
}, | |
tabline = {}, | |
extensions = {} | |
} | |
end | |
setup_status_line() | |
local t = function(str) | |
return vim.api.nvim_replace_termcodes(str, true, true, true) | |
end | |
local check_back_space = function() | |
local col = vim.fn.col('.') - 1 | |
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then | |
return true | |
else | |
return false | |
end | |
end | |
-- Use (s-)tab to: | |
--- move to prev/next item in completion menuone | |
--- jump to prev/next snippet's placeholder | |
_G.tab_complete = function() | |
if vim.fn.pumvisible() == 1 then | |
return t "<C-n>" | |
elseif vim.fn.call("vsnip#available", {1}) == 1 then | |
return t "<Plug>(vsnip-expand-or-jump)" | |
elseif check_back_space() then | |
return t "<Tab>" | |
else | |
return vim.fn['compe#complete']() | |
end | |
end | |
_G.s_tab_complete = function() | |
if vim.fn.pumvisible() == 1 then | |
return t "<C-p>" | |
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then | |
return t "<Plug>(vsnip-jump-prev)" | |
else | |
return t "<S-Tab>" | |
end | |
end | |
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true}) | |
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true}) | |
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true}) | |
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true}) | |
require'nvim-web-devicons'.setup { | |
-- your personnal icons can go here (to override) | |
-- DevIcon will be appended to `name` | |
override = { | |
zsh = { | |
icon = "", | |
color = "#428850", | |
name = "Zsh" | |
} | |
}; | |
-- globally enable default icons (default to false) | |
-- will get overriden by `get_icons` option | |
default = true; | |
} | |
require("trouble").setup { | |
} | |
local actions = require("telescope.actions") | |
local trouble = require("trouble.providers.telescope") | |
local telescope = require("telescope") | |
telescope.setup { | |
defaults = { | |
mappings = { | |
i = { ["<c-t>"] = trouble.open_with_trouble }, | |
n = { ["<c-t>"] = trouble.open_with_trouble }, | |
}, | |
}, | |
} | |
setup_servers() | |
-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim | |
require'lspinstall'.post_install_hook = function () | |
setup_servers() -- reload installed servers | |
vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server | |
end | |
local tree_cb = require'nvim-tree.config'.nvim_tree_callback | |
vim.g.nvim_tree_bindings = { | |
-- ["<CR>"] = ":YourVimFunction()<cr>", | |
-- ["u"] = ":lua require'some_module'.some_function()<cr>", | |
-- default mappings | |
["<CR>"] = tree_cb("edit"), | |
["o"] = tree_cb("edit"), | |
["<2-LeftMouse>"] = tree_cb("edit"), | |
["<2-RightMouse>"] = tree_cb("cd"), | |
["<C-]>"] = tree_cb("cd"), | |
["<C-v>"] = tree_cb("vsplit"), | |
["<C-x>"] = tree_cb("split"), | |
["<C-t>"] = tree_cb("tabnew"), | |
["<"] = tree_cb("prev_sibling"), | |
[">"] = tree_cb("next_sibling"), | |
["<BS>"] = tree_cb("close_node"), | |
["<S-CR>"] = tree_cb("close_node"), | |
["<Tab>"] = tree_cb("preview"), | |
["I"] = tree_cb("toggle_ignored"), | |
["H"] = tree_cb("toggle_dotfiles"), | |
["R"] = tree_cb("refresh"), | |
["a"] = tree_cb("create"), | |
["d"] = tree_cb("remove"), | |
["r"] = tree_cb("rename"), | |
["<C-r>"] = tree_cb("full_rename"), | |
["x"] = tree_cb("cut"), | |
["c"] = tree_cb("copy"), | |
["p"] = tree_cb("paste"), | |
["[c"] = tree_cb("prev_git_item"), | |
["]c"] = tree_cb("next_git_item"), | |
["-"] = tree_cb("dir_up"), | |
["q"] = tree_cb("close"), | |
} | |
EOF | |
" --------------- ---- -- LSP --- --- -- -- - | |
endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you come from bash you might have to change your $PATH. | |
export FLUTTERPATH=$HOME/Documents/pprojects/flutter/bin | |
export CARGOBINPATH=$HOME/.cargo/bin | |
export POSTGRESPATH='/usr/local/opt/postgresql@11/bin' | |
export GOPATH=$HOME/Documents/pprojects/goprojects | |
export GOBIN=$GOPATH/bin | |
export PATH=$POSTGRESPATH:/usr/local/sbin:/usr/local/opt/[email protected]/bin:/usr/local/opt/grep/libexec/gnubin:/Users/srd0045/Library/Python/3.8/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/ruby/bin:$HOME/.local/bin:$HOME/bin:/usr/local/bin:$HOME/Applications:/usr/local/go/bin:~/go/bin/bin:$HOME/.composer/vendor/bin:$FLUTTERPATH:$CARGOBINPATH:$GOPATH/bin:$PATH | |
export GO111MODULE=on | |
# Path to your oh-my-zsh installation. | |
export ZSH="/Users/srd0045/.oh-my-zsh" | |
export BAT_THEME="Coldark-Dark" | |
export CLICOLOR_FORCE=1 | |
export CLICOLOR=1 | |
export LSCOLORS='GxFxCxDxBxegedabagaced' | |
export LS_COLORS='di=1:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31' | |
export TREE_COLORS=$LS_COLORS | |
# For compilers to find postgresql@11 you may need to set: | |
export LDFLAGS="-L/usr/local/opt/postgresql@11/lib" | |
export CPPFLAGS="-I/usr/local/opt/postgresql@11/include" | |
# For pkg-config to find postgresql@11 you may need to set: | |
export PKG_CONFIG_PATH="/usr/local/opt/postgresql@11/lib/pkgconfig" | |
# heroku autocomplete setup | |
# shellcheck disable=SC1090 | |
HEROKU_AC_ZSH_SETUP_PATH=/Users/srd0045/Library/Caches/heroku/autocomplete/zsh_setup && test -f $HEROKU_AC_ZSH_SETUP_PATH && source $HEROKU_AC_ZSH_SETUP_PATH; | |
# Set name of the theme to load --- if set to "random", it will | |
# load a random theme each time oh-my-zsh is loaded, in which case, | |
# to know which specific one was loaded, run: echo $RANDOM_THEME | |
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes | |
# shellcheck disable=SC2034 | |
ZSH_THEME="agnoster" | |
# ZSH_THEME="random" | |
# Set list of themes to pick from when loading at random | |
# Setting this variable when ZSH_THEME=random will cause zsh to load | |
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/ | |
# If set to an empty array, this variable will have no effect. | |
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) | |
# Uncomment the following line to use case-sensitive completion. | |
# CASE_SENSITIVE="true" | |
# Uncomment the following line to use hyphen-insensitive completion. | |
# Case-sensitive completion must be off. _ and - will be interchangeable. | |
# HYPHEN_INSENSITIVE="true" | |
# Uncomment the following line to disable bi-weekly auto-update checks. | |
# DISABLE_AUTO_UPDATE="true" | |
# Uncomment the following line to change how often to auto-update (in days). | |
# export UPDATE_ZSH_DAYS=13 | |
# Uncomment the following line to disable colors in ls. | |
# DISABLE_LS_COLORS="true" | |
# Uncomment the following line to disable auto-setting terminal title. | |
# DISABLE_AUTO_TITLE="true" | |
# Uncomment the following line to enable command auto-correction. | |
# ENABLE_CORRECTION="true" | |
# Uncomment the following line to display red dots whilst waiting for completion. | |
# shellcheck disable=SC2034 | |
COMPLETION_WAITING_DOTS="true" | |
# Uncomment the following line if you want to disable marking untracked files | |
# under VCS as dirty. This makes repository status check for large repositories | |
# much, much faster. | |
# DISABLE_UNTRACKED_FILES_DIRTY="true" | |
# Uncomment the following line if you want to change the command execution time | |
# stamp shown in the history command output. | |
# You can set one of the optional three formats: | |
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" | |
# or set a custom format using the strftime function format specifications, | |
# see 'man strftime' for details. | |
# HIST_STAMPS="mm/dd/yyyy" | |
# Would you like to use another custom folder than $ZSH/custom? | |
# ZSH_CUSTOM=/path/to/new-custom-folder | |
# shellcheck disable=SC2034 | |
MAGIC_ENTER_GIT_COMMAND='gitlnn 10 && echo "${RESET}" && git status -u .' | |
# Which plugins would you like to load? | |
# Standard plugins can be found in ~/.oh-my-zsh/plugins/* | |
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ | |
# Example format: plugins=(rails git textmate ruby lighthouse) | |
# Add wisely, as too many plugins slow down shell startup. | |
# shellcheck disable=SC2034 | |
plugins=( | |
aws | |
bundler | |
command-time | |
common-aliases | |
docker | |
docker-compose | |
git | |
git-extras | |
golang | |
gpg-agent | |
kubectl | |
magic-enter | |
minikube | |
rbenv | |
terraform | |
zsh-syntax-highlighting | |
) | |
# Go jira auto-completion | |
eval "$(jira --completion-script-zsh)" | |
eval "$(spotify completion zsh)" | |
# shellcheck disable=SC1090 | |
source $HOME/my_scripts/generate-release-diffs.sh | |
# shellcheck disable=SC1090 | |
source $HOME/my_scripts/export-zshrc.sh | |
# shellcheck disable=SC1090 | |
source $ZSH/oh-my-zsh.sh | |
# User configuration | |
# export MANPATH="/usr/local/man:$MANPATH" | |
# You may need to manually set your language environment | |
# export LANG=en_US.UTF-8 | |
# Preferred editor for local and remote sessions | |
# if [[ -n $SSH_CONNECTION ]]; then | |
# export EDITOR='nvim' | |
# else | |
# export EDITOR='mvim' | |
# fi | |
# Use vim as visual editor when editing command line | |
vim-command-line () { | |
local VISUAL='nvim' | |
edit-command-line | |
} | |
zle -N vim-command-line | |
bindkey '^X^E' vim-command-line | |
# The next line updates PATH for the Google Cloud SDK. | |
if [ -f '/Users/srd0045/google-cloud-sdk/path.zsh.inc' ]; then | |
source '/Users/srd0045/google-cloud-sdk/path.zsh.inc'; | |
fi | |
# The next line enables shell command completion for gcloud. | |
if [ -f '/Users/srd0045/google-cloud-sdk/completion.zsh.inc' ]; then | |
. '/Users/srd0045/google-cloud-sdk/completion.zsh.inc'; | |
fi | |
# shellcheck disable=SC1090 | |
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh | |
export FZF_DEFAULT_OPTS=' | |
--height=40% | |
--preview="([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && tree -C -L 2 {} )" | |
--preview-window=right:60%:wrap' | |
# tabtab source for packages | |
# uninstall by removing these lines | |
# shellcheck disable=SC1090 | |
[[ -f ~/.config/tabtab/__tabtab.zsh ]] && . ~/.config/tabtab/__tabtab.zsh || true | |
# [ -f ~/.rg.zsh ] && source ~/.rg.zsh | |
# Compilation flags | |
# export ARCHFLAGS="-arch x86_64" | |
REVOLVER_INSTALLED=`if [[ -n "$(command -v revolver)" ]]; then echo "true"; else echo "false"; fi` | |
UNBUFFER_INSTALLED=`if [[ -n "$(command -v unbuffer)" ]]; then echo "true"; else echo "false"; fi` | |
GOJIRA_INSTALLED=`if [[ -n "$(command -v jira)" ]]; then echo "true"; else echo "false"; fi` | |
HEROKU_INSTALLED=`if [[ -n "$(command -v heroku)" ]]; then echo "true"; else echo "false"; fi` | |
SLACKCAT_INSTALLED=`if [[ -n "$(command -v slackcat)" ]]; then echo "true"; else echo "false"; fi` | |
# Set personal aliases, overriding those provided by oh-my-zsh libs, | |
# plugins, and themes. Aliases can be placed here, though oh-my-zsh | |
# users are encouraged to define aliases within the ZSH_CUSTOM folder. | |
# For a full list of active aliases, run `alias`. | |
# Example aliases | |
# alias zshconfig="mate ~/.zshrc" | |
# alias ohmyzsh="mate ~/.oh-my-zsh" | |
alias :ff='qf' | |
alias :q='exit' | |
alias act='act --platform ubuntu-latest=nektos/act-environments-ubuntu:18.04' | |
alias am='better_hub_am' | |
alias batz='bat --language zsh' | |
alias bh='backup_heroku ' | |
alias bt='bigtext' | |
alias btw='bigtextw' | |
alias bty='bigtexty' | |
alias cb='git rev-parse --symbolic-full-name --abbrev-ref HEAD' | |
alias cpr='create_pr_from_branch' | |
alias cproj="basename -s '.git' $(git config --get remote.origin.url)" | |
alias cr="git config --get remote.origin.url | awk -F ':' '{print \$NF}' | sed -e 's/\.git$//'" # Current repository | |
alias db='default_branch' # default branch for this repository | |
alias dbcf='SEEDING=1 railsdevenv && dbd && dbcr && dbm && dbs && dbtp' | |
alias dbc='bin/reset_db' | |
alias dbcr='bundle exec rake db:create' | |
alias dbd='bundle exec rake db:drop' | |
alias dbenvset='rails db:environment:set' | |
alias dbs='bundle exec rake db:seed' | |
alias dbtp='bundle exec rake db:test:prepare' | |
alias dic='dictionary_lookup' | |
alias epicdate='date -u +"Created at %Y-%m-%d %H:%M:%S UTC"' | |
alias epr='pra | grep "\[Epic\]"' # List only open epic PRs | |
alias railsdevenv='dbenvset RAILS_ENV=development' | |
alias dbm='bundle exec rake db:migrate' | |
alias dbr='bundle exec rake db:rollback' | |
alias dependabotcheck='es && ts && it && ys' | |
alias diffenv='diff_heroku_env_vars' | |
alias es='eslint' | |
alias fzf="fzf --color='bg:#4B4B4B,bg+:#3F3F3F,info:#BDBB72,border:#6B6B6B,spinner:#98BC99,hl:#719872,fg:#D9D9D9,header:#719872,fg+:#D9D9D9,pointer:#E12672,marker:#E17899,prompt:#98BEDE,hl+:#98BC99'" | |
alias gac='git add . && gc' | |
alias gacm='git_add_all_and_commit_with_message' | |
alias gacp='gac && gp' | |
alias gb='git for-each-ref --format="%(refname:short)" refs/heads/' | |
alias gbc='git --no-pager branch --contains ' | |
alias gc='git commit -v -s -S' | |
alias gco='git_checkout_or_create_branch' | |
alias gcoj='git_checkout_from_jira' | |
alias gcopr='checkout_pr' #Give it a PR id and it'll checkout the branch | |
alias gdev='gco develop && gl' | |
alias gdevc='gco develop && gl && dbc' | |
alias gdf='git_diff_filenames_only' # Changed files | |
alias gff='git --no-pager log --follow --pretty=tformat:"%C(Yellow)%h %C(Magenta)%cd %<(1)%C(Green)%G? %<(8,trunc)%Cblue%cn %C(Cyan)%s" --no-decorate --date=short --' | |
alias gg='git --no-pager log --pretty=tformat:"%>>|(20)%C(Yellow)%h %C(Magenta)%cd %<(1)%C(Green)%G? %<(10,trunc)%Cblue%cn %C(Cyan)%s" --no-decorate --date=short --graph' | |
alias ggn='gg -n' # pretty graph output, limited to last N commits | |
alias gic='gf && git_initial_commit' | |
# alias git='hub' | |
# a pretty, more easily readable gitlog when trying to find which commits need to be squashed: | |
alias gitl='git --no-pager log --pretty=tformat:"%C(Yellow)%h %C(Magenta)%cd %<(1)%C(Green)%G? %<(10,trunc)%Cblue%cn %<(80,trunc)%C(Cyan)%s" --no-decorate --date=short' | |
alias gitln='gitl -n' | |
alias gitlnn='git_log_n_with_line_numbers' # adds line numbers to pretty gitl | |
alias glb='grep_branches' | |
alias gpu='git push --force --set-upstream origin $(git rev-parse --symbolic-full-name --abbrev-ref HEAD)' | |
alias grr='git fetch && git reset --hard origin/`cb`' | |
alias gs='git stash' | |
alias gsp='git stash pop' | |
alias gsq='git squash' | |
alias prodc='heroku run rails console --app spielberg-api' | |
alias hb='hub_browse' | |
alias hfit='HEADLESS=false it' # HeadFUL mode for it | |
alias it='yarn test:integration' | |
alias it2='it && it' | |
$GOJIRA_INSTALLED && alias jv='jira view' | |
alias lc='list_changed_files' | |
alias lint='es && ts' | |
alias lt='tree' | |
alias mk='minikube' | |
alias mkdir='mkdir -pv' | |
alias ml='merge_last' | |
alias ml2='merge_last 2' | |
$GOJIRA_INSTALLED && alias nt='jira next' | |
$GOJIRA_INSTALLED && alias ntb='jira nextbe' | |
$GOJIRA_INSTALLED && alias ntf='jira nextfe' | |
alias nvid='neovide' | |
alias oc='open_changed_files' | |
alias pb='gco -' | |
alias pd='pr_in_branch --branch "develop" --pr ' | |
alias pg_start="launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist" | |
alias pg_stop="launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist" | |
alias pm='pr_in_branch --branch "master" --pr ' | |
alias pp='pr_in_branch --branch "preview" --pr ' | |
$UNBUFFER_INSTALLED && \ | |
alias pra='revolver --style 'dots' --hide-cursor start "Fetching... " && unbuffer hub pr list -s "open" -f "%pC%>(8)%i%Creset %Cblue%<(10,trunc)%au%Creset %t %l%n" && revolver stop' | |
alias prci='pr_ci_status' | |
$UNBUFFER_INSTALLED && \ | |
alias prmr='revolver --style 'dots' --hide-cursor start "Fetching... " && unbuffer hub pr list -s "open" -o "updated" -f "%pC%>(6)%i%Creset %Cmagenta%uD %Cblue%<(10,trunc)%au%Creset %Ccyan%t%Creset {%rs}%n" | grep -v -E "\[Epic\]" | grep -E "\{[^\}]*${GITHUB_USER}.*}" | sed "s/{.*//" && revolver stop' | |
alias prr='hub pr list -s "open" --color=always | grep "please-review" --color=never' | |
alias pulls='open_pull_request_page' | |
alias python='python3' | |
alias qf='gacm && ml2 && gpf' | |
alias rad='gco && grr && gco $CB && grb develop' | |
alias rc='railsdevenv && rails console' | |
alias rd='date +%Y-%m-%d' | |
alias dt='date "+%Y-%m-%d %H:%M:%S"' | |
alias repo=open "$(hub api '/repos/{owner}/{repo}' --flat | grep '^\.html_url' | awk '{print $2}')" | |
alias rfd='heroku pg:copy spielberg-api::HEROKU_POSTGRESQL_BROWN DATABASE --app spielberg-api-demo' | |
alias rs='railsdevenv && bin/rails s || rails s' | |
alias rspec='bundle exec rspec' | |
alias aws='aws --profile PowerUserAccess-522918171347' | |
alias sb='switch_to_nth_branch' | |
alias scbackend='npm run dev-backend' #showcase | |
alias scfrontend='npm run dev-ui' #showcase runs on port 3000 | |
alias sidekiq="SCHEDULER=true RAILS_ENV=development bundle exec sidekiq -C config/sidekiq.yml" | |
alias spec='rails db:environment:set RAILS_ENV=test && bundle exec rspec' | |
alias src='source ~/.zshrc' | |
alias srce="${EDITOR} ~/.zshrc" | |
alias srcex='export_zshrc' | |
$GOJIRA_INSTALLED && alias take='start_jira_issue' | |
alias ts='tslint' | |
alias tsfix='yarn tslint-fix' | |
alias tslint='yarn tslint' | |
alias us='yarn jest --updateSnapshot' | |
alias vim='nvim' | |
alias vi='nvim' | |
alias v='nvim .' | |
alias wopr='work_on_pr' | |
alias yi='yarn install' | |
alias yb='yarn build' | |
alias yba='yarn clean-nm && yarn build-libs && yarn build' | |
alias yl='yarn link' | |
alias ys='yarn start' | |
alias yt='yarn test' | |
# shellcheck disable=SC2034 | |
DEFAULT_USER=$(whoami) # strips the username from the command prompt to relinquish screen-estate for useful things. | |
BRANCH_USER='adam' # set this to what you want to appear in your branch-names | |
# e.g. adam/studio-111/this-is-a-git-branch | |
GITHUB_USER='ajh-sr' # Used by -- e.g. prmr -- to filter results based on the github username | |
# Jira states: | |
# READY_FOR_DEVELOPMENT_STATE="Ready for development" | |
IN_DEVELOPMENT_STATE="In development" | |
# TECH_REVIEW_STATE="Tech review" | |
# Shortcuts for terminal colour values | |
RED="\033[1;31m" | |
ERROR=$RED | |
GREEN="\033[1;32m" | |
SUCCESS=$GREEN | |
ORANGE="\033[1;33m" | |
WARNING=$ORANGE | |
# WHITE="\033[0;37m" | |
RESET="\033[0m" | |
declare -g CB # global variable to hold the current branch | |
declare -g PB # global variable holding the previous branch | |
# used to be able to switch back and forth between branches quickly. | |
function redact(){ | |
if (($# == 0)) then | |
echo "${WARNING}⚠️ ${0} needs something to redact${RESET}" | |
return 1 | |
else | |
echo ${@} | sed -E 's/.{10}$/xxxxxxxxxx/g' | |
fi | |
} | |
function dictionary_lookup(){ | |
if (($# == 0)) then | |
echo "${WARNING}⚠️ ${0} needs a word to look up${RESET}" | |
return 1 | |
else | |
curl "dict://dict.org/d:${1}" | |
fi | |
} | |
function lrs(){ | |
echo "$(dt), ${@}," >> "/Users/srd0045/Documents/Projects/temp/release-timing/$(rd).csv" | |
} | |
function prs_awaiting_my_review() { | |
if (($# == 0)) then | |
$UNBUFFER_INSTALLED && \ | |
revolver --style 'dots' --hide-cursor start "Fetching... " && \ | |
unbuffer hub pr list -s ""$(command -v revolver)"open" -o "updated" -f \ | |
"%pC%>(6)%i%Creset %Cmagenta%uD %Cblue%<(10,trunc)%au%Creset %Ccyan%t%Creset {%rs}%n" | \ | |
grep -v -E "\[Epic\]" | \ | |
grep -E "\{[^\}]*${GITHUB_USER}.*}" | \ | |
sed "s/{.*//" && \ | |
revolver stop | |
else | |
echo "Arg passed" | |
fi | |
} | |
function checkout_pr(){ | |
echo -n "#${1}" | pbcopy | |
hub pr checkout $1 | |
} | |
function create_epic_branch(){ | |
if (($# == 0 )) then | |
echo "${WARNING}⚠️ ${0} requires a JIRA id to create an epic from.${RESET}" | |
return 1 | |
else | |
git checkout develop && \ | |
grr && \ | |
git checkout -b | |
echo "https://shuttlerock.atlassian.net/browse/STUDIO-${1}\n\n$(date -u +'Created at %Y-%m-%dT%H:%M:%S UTC')" >> .meta/STUDIO-${1}.md && \ | |
gpu | |
fi | |
} | |
function releases(){ | |
if (($# == 0)) then | |
LIMIT=10 | |
else | |
LIMIT="${1}" | |
fi | |
hub release -f "%t %U%n" -L ${LIMIT} | tr '()' '|' | awk -F '|' '{printf("\033[34m %-18s \033[33m%-30s \033[36m%s \n", $1, $2, $NF)}' | |
} | |
function killport(){ | |
if (($# == 0)) then | |
echo "${ERROR} Please specify a port number. ${RESET}" | |
return 1 | |
else | |
PROCESS_ID=`netstat -vanp tcp | grep "${1}" | awk '{print $9}'` | |
if [[ ! -z "${PROCESS_ID// }" ]]; then | |
netstat -vanp tcp | grep "${1}" | awk '{print $9}' | xargs kill | |
else | |
echo "${WARNING} Nothing found on port ${1}.${RESET}" | |
return 1 | |
fi | |
fi | |
} | |
# Start an interactive rebase to squash the last N commits. | |
# N defaults to 2 | |
function merge_last(){ | |
if (($# == 0 )) then | |
N=2 | |
else | |
N=${1} | |
fi | |
grbi HEAD~${N} | |
} | |
function backup_heroku(){ | |
declare -A fopts | |
declare -a foptsKeys | |
fopts[--app]="spielberg-api" # studio production app [default] | |
zparseopts -K -A fopts -- -app: v | |
foptsKeys=${(k)fopts} | |
VERBOSE=false | |
ADDITONAL_ARGS='' | |
if [[ ${foptsKeys[(i)-v]} -le ${#foptsKeys} ]]; then | |
VERBOSE=true | |
ADDITONAL_ARGS="--verbose " | |
fi | |
heroku pg:backups:capture --app ${fopts[--app]} ${ADDITONAL_ARGS} | |
} | |
# Adds all files and commits with a message, defaults to WIP | |
# | |
# Usage: `gacm a commit message` (no quotes required) | |
function git_add_all_and_commit_with_message(){ | |
if (($# == 0 )) then | |
gac -m "$(git_message_prefix) WIP" | |
else | |
MESSAGE="${@}" | |
gac -m "$(git_message_prefix)${MESSAGE}" | |
fi | |
} | |
# Usage: `bigtext Some little text` | |
# Outputs custom emoji names for use in slack: `:square-s::square-o::square-m::square-e: :square-l::square-i::square-t::square-t::square-l::square-e: :square-t::square-e::square-x::square-t:` | |
function bigtext() { | |
if (($# == 0 )) then | |
echo "No argument?!" | |
else | |
echo "${@}" | tr '[:upper:]' '[:lower:]' | sed "s/[a-z]/:square-&:/g" | pbcopy | |
fi | |
} | |
function bigtextw(){ | |
if (($# == 0 )) then | |
echo "No argument?!" | |
else | |
echo "${@}" | tr '[:upper:]' '[:lower:]' | sed "s/[a-z]/:alphabet-white-&:/g" | pbcopy | |
fi | |
} | |
function bigtexty(){ | |
if (($# == 0 )) then | |
echo "No argument?!" | |
else | |
echo "${@}" | tr '[:upper:]' '[:lower:]' | sed "s/[a-z]/:alphabet-yellow-&:/g" | pbcopy | |
fi | |
} | |
# Given a command, and an optional distance back in | |
# the command line history, returns the | |
# most used arguments for the command. | |
# | |
# Used to identify possible candidates for aliases/shortcuts | |
function most_used_arguments(){ | |
if (($# == 0 )) then | |
echo "${WARNING}⚠️ ${0} requires at least a command/command pattern to search on.${RESET}" | |
return 1 | |
else | |
COMMAND_GREP=$1 | |
TOP=10 | |
if [[ ! -z "${2// }" ]]; then | |
TOP=$2 | |
fi | |
fi | |
history \ | |
| sed -E -e 's/^([ \t]*[0-9]*[ \t]*)//' \ | |
| grep -E "^${COMMAND_GREP}[ \t]" \ | |
| awk -F ' ' '{print $2}' \ | |
| sort | uniq -c | sort -r \ | |
| head -n "${TOP}" | |
} | |
# Given an optional "Top N" argument and a distance back in the command line history, returns | |
# the Top N most used commands over that distance. Defaults to Top 25, and all time. | |
# | |
# Used to identify possible candidates for aliases/shortcuts | |
function most_used_commands(){ | |
if (($# == 0 )) then | |
TOP=25 | |
else | |
TOP=$1 | |
DISTANCE_BACK="-$2" | |
fi | |
history ${DISTANCE_BACK} \ | |
| awk '{print $2}' \ | |
| sort | uniq -c | sort -r \ | |
| head -${TOP} | |
} | |
# Checks a PR's CI status, with links (Ctrl/Command + click to open) | |
# | |
# If you don't give it a PR id as an argument it defaults to trying to show the PR | |
# associated with the current branch | |
function pr_ci_status(){ | |
if ! command -v hub &> /dev/null; then | |
echo "${ERROR} hub not found${RESET}" | |
return 1 | |
fi | |
unbuffer hub ci-status `hub pr show ${1} -f "%sH"` -v | awk -F '\?' '{print $1}' | |
} | |
#function pr_ci_status_watch(){ | |
# if ! command -v hub &> /dev/null; then | |
# echo "${ERROR} hub not found${RESET}" | |
# return 1 | |
# fi | |
# COMMIT=`hub pr show ${1} -f "%sH"` | |
# if [[ -n "${COMMIT// }" ]]; then | |
# $REVOLVER_INSTALLED && revolver --style 'dots' --hide-cursor start "Waiting for Github/Circle CI... " | |
# fi | |
# hub ci-status $COMMIT -v &>/dev/null | |
#} | |
# Lists all filenames in a diff | |
# | |
# Diff spec defaults to HEAD^ (changes made in most recent commit) if none is provided | |
function git_diff_filenames_only(){ | |
if (($# == 0 )) then | |
DIFFSPEC='HEAD^' | |
else | |
DIFFSPEC=$1 | |
fi | |
git --no-pager diff --name-only --diff-filter=d ${DIFFSPEC} | |
} | |
# Function to list a pretty git log prepended with line numbers | |
# | |
# Requires `unbuffer` (`brew install expect`); if unbuffer isn't found, it just calls gitln | |
function git_log_n_with_line_numbers(){ | |
if (($# == 0 )) then | |
echo "gitlnn requires a number to limit results by" | |
return 1 | |
else | |
if ! command -v unbuffer &> /dev/null; then | |
gitln $1 | |
else | |
unbuffer git --no-pager log \ | |
--pretty=tformat:"%C(Yellow)%h %C(Magenta)%cd %<(1)%C(Green)%G? %<(10,trunc)%Cblue%cn %<(80,trunc)%C(Cyan)%s%C(reset)" \ | |
--no-decorate --date=short -n $1 | nl -w${#1} -s" " | |
fi | |
fi | |
} | |
# Does not update ALL branches, just develop, preview, and master. | |
# | |
# Use prior to running e.g. pr_in_branch, | |
function update_all_branches () { | |
OLD_BRANCH=`cb` | |
git checkout develop && \ | |
git fetch && \ | |
git reset --hard origin/develop && \ | |
git checkout preview && \ | |
git reset --hard origin/preview && \ | |
git checkout master && \ | |
git reset --hard origin/master | |
git checkout "${OLD_BRANCH}" | |
} | |
# Function: default_branch | |
# | |
# Gets the default branch for the currently checked-out Github repository | |
# Dependencies: | |
# `hub` https://github.com/github/hub | |
function default_branch(){ | |
if ! command -v hub &> /dev/null; then | |
hub api /repos/{owner}/{repo} --flat | grep '.default_branch' | awk '{print $2}' | uniq | |
else | |
git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' | |
fi | |
} | |
function open_pull_request_page(){ | |
open "$(hub api /repos/{owner}/{repo} --flat | grep '^\.html_url' | awk '{print $2}')/pulls" | |
} | |
function epic-status(){ | |
true; | |
} | |
# Function takes a number, n, and shows the last n items in the history along with the | |
# relative distance for the ! command | |
function b(){ | |
if (($# == 0)) then | |
relative=20 #default history to show | |
else | |
relative=$1 | |
fi | |
fc -l -$relative | awk "{print $HISTCMD-\$1+1, \$0}" | |
} | |
function list_changed_files(){ | |
if (($# == 0 )) then | |
github_diffspec='HEAD^' | |
else | |
github_diffspec=$1 | |
fi | |
git --no-pager diff ${github_diffspec} --name-only --diff-filter=d | |
} | |
function open_changed_files(){ | |
if (($# == 0 )) then | |
github_diffspec='HEAD^' | |
else | |
github_diffspec=$1 | |
fi | |
FILES_AFFECTED=`git --no-pager diff ${github_diffspec} --name-only --diff-filter=d | wc -l | tr -d '[:blank:]'` | |
if (( $FILES_AFFECTED < 50 )); then | |
git --no-pager diff ${github_diffspec} --name-only --diff-filter=d | xargs nvim -p | |
else | |
echo "This would open ${FILES_AFFECTED} files, aborting." | |
fi | |
} | |
# Checks out the latest remote version of the PR given, opens up the changed files in whatever visual editor | |
# is set up in $VISUAL and opens up the PR on github in the user's browser | |
function work_on_pr(){ | |
if (($# == 0 )) then | |
PR_NUMBER=`hub pr show -f "%I"` | |
else | |
PR_NUMBER=$1 | |
fi | |
if [[ -z "${PR_NUMBER// }" ]]; then | |
echo "Couldn't intuit a PR number from current branch and none given as an argument " | |
return 1 | |
fi | |
gcopr ${PR_NUMBER} && \ | |
grr && \ | |
open_changed_files && \ | |
hub pr show | |
} | |
# Given a diffspec, this checks for any files that have changed and runs rubocop on them | |
function rubocop_changed_files() { | |
if (($# == 0 )) then | |
github_diffspec='HEAD^' | |
else | |
github_diffspec=$1 | |
fi | |
git --no-pager diff ${github_diffspec} --name-only --diff-filter=d | grep -v -E "(schema|yml)" | xargs rubocop | |
} | |
# Given a diffspec, this checks for any rspec files that have changed and runs them | |
function rspec_changed_spec_files() { | |
if (($# == 0 )) then | |
github_diffspec='HEAD^' | |
else | |
github_diffspec=$1 | |
fi | |
git --no-pager diff ${github_diffspec} --name-only --diff-filter=d | grep "_spec.rb" | xargs bundle exec rspec | |
} | |
# Given a diffspec, lint any files that have changed | |
function lint_changed_files() { | |
if (($# == 0 )) then | |
github_diffspec='HEAD^' | |
else | |
github_diffspec=$1 | |
fi | |
git --no-pager diff ${github_diffspec} --name-only --diff-filter=d | xargs yarn eslint --fix | |
} | |
function pre(){ | |
if (($# == 0 )) then | |
echo "Check if sha is in preview branch"; | |
echo "Usage ${0} <sha>"; | |
return; | |
else | |
gbc ${1} | grep "preview" | |
fi | |
} | |
function bre(){ | |
if (($# == 0 )) then | |
echo "Check if branch has been merged to preview branch"; | |
echo "Usage ${0} <sha>"; | |
return; | |
else | |
git branch -r --merged preview | grep ${1} | |
fi | |
} | |
# Function takes a pattern, finds matching local branches and tries to delete them | |
function gbdt(){ | |
if (( $# == 0 )) then | |
echo "Usage: gbdt <pattern>"; | |
else | |
git checkout `default_branch`; | |
git for-each-ref --format="%(refname:short)" refs/heads/ | grep --color=never -e $1 | xargs git branch -d | |
fi | |
} | |
# Function takes a pattern, finds matching local branches and deletes them, without | |
# any regard to whether they have been merged. Use with caution. | |
function gbddt(){ | |
if (( $# == 0 )) then | |
echo "Usage: gbddt <pattern>"; | |
else | |
git checkout `default_branch`; | |
git for-each-ref --format="%(refname:short)" refs/heads/ | grep --color=never -e $1 | xargs git branch -D | |
fi | |
} | |
# With no arguments, checkout the default branch | |
# With a branch name, checks if it already exists in refs/heads after a git fetch. | |
# If not, it tries to check the branch name out. | |
# If this fails, it creates a branch with the given branch name | |
function git_checkout_or_create_branch(){ | |
PB=`cb` | |
if (($# == 0 )) then | |
git checkout `db` | |
else | |
git fetch | |
matching_pattern_branch=`git branch -r | grep "${1}"` | |
if [[ -z "${matching_pattern_branch// }" ]]; then | |
git checkout -b "${1}" #&>/dev/null | |
else | |
normalised_branch_name=$(normalise_branch_component "${1}") | |
git checkout "${1}" &>/dev/null || git checkout -b "${normalised_branch_name}" | |
fi | |
CB=`cb` | |
fi | |
} | |
# Uses [go-jira/jira](https://github.com/go-jira/jira) to get details from jira for | |
# an Issue ID, creates a reasonable branch name, then checks out/creates a branch | |
# using that infogit_checkout_from_jira. | |
# | |
# Usage: git_checkout_from_jira STUDIO-432, or: git_checkout_from_jira 432 if you've | |
# set up `project: STUDIO` in ./.jira.d/config.yml or have similarly linked the current | |
# git repo to the JIRA project. E.g. (https://github.com/go-jira/jira#dynamic-configuration) | |
function git_checkout_from_jira(){ | |
if ! $GOJIRA_INSTALLED; then | |
echo 'Is go-jira installed? (https://github.com/go-jira/jira)' | |
fi | |
if (($# == 0 )) then | |
echo 'Sorry, need a JIRA issue id' | |
else | |
$REVOLVER_INSTALLED && revolver --style 'dots' --hide-cursor start "Checking out... " | |
ISSUE_DETAILS=`jira view ${1}` | |
ISSUE_SUMMARY=$(grep -E '^summary:' <<< "${ISSUE_DETAILS}" | awk -F ': ' '{print $2}') | |
ISSUE_NAME=$(grep -E '^issue:' <<< "${ISSUE_DETAILS}" | awk -F ': ' '{print $2}') | |
normalised_branch_name=$(normalise_branch_component "${ISSUE_SUMMARY}") | |
normalised_issue=$(normalise_branch_component "${ISSUE_NAME}") | |
git_checkout_or_create_branch "${BRANCH_USER}/${normalised_issue}/${normalised_branch_name}" | |
$REVOLVER_INSTALLED && revolver stop | |
fi | |
} | |
# Requires [go-jira/jira](https://github.com/go-jira/jira) to interact with jira | |
# | |
# Assigns the task to the current authenticated user and checks out into a new branch | |
function start_jira_issue(){ | |
if ! $GOJIRA_INSTALLED; then | |
echo 'Is go-jira installed? (https://github.com/go-jira/jira)' | |
return 1 | |
fi | |
if (($# == 0 )) then | |
echo 'Sorry, need a JIRA issue id' | |
else | |
jira take $1 && \ | |
jira transition --noedit $IN_DEVELOPMENT_STATE $1 | |
# && \ | |
# git_checkout_from_jira $1 | |
#wait_for_pr $1 | |
fi | |
} | |
function wait_for_pr(){ | |
if (($# == 0 )) then | |
echo 'Sorry, need a string to look for in the PR title' | |
else | |
$REVOLVER_INSTALLED && revolver --style 'dots' --hide-cursor start "Waiting for Git... " | |
for ((i = 0; i < 5; i++)); do | |
PR_ID=`hub pr list | grep ${1} | awk '{print $1}' | tr -d '#'` | |
if [[ -n "${PR_ID// }" ]]; then | |
$REVOLVER_INSTALLED && revolver stop | |
$REVOLVER_INSTALLED && revolver --style 'dots' --hide-cursor start "Checking out: #${PR_ID}" | |
git fetch && \ | |
hub pr checkout $PR_ID && \ | |
git branch -u origin $(git rev-parse --symbolic-full-name --abbrev-ref HEAD) | |
break; | |
fi | |
sleep 15; | |
done | |
$REVOLVER_INSTALLED && revolver stop | |
fi | |
} | |
# Give it a string and it normalises so it can be used in a git branch name | |
# - swaps '&'s for 'and's | |
# - takes out apostrophes | |
# - takes out excess spaces | |
# - swaps spaces for hyphens | |
# - downcases everything | |
function normalise_branch_component(){ | |
if (($# == 0 )) then | |
echo 'No argument given' | |
else | |
normalised_branch_component=`echo ${1} | sed -e 's/&/and/g' -e 's/\:/-/g' -e "s/\[[^]]*\]//g" -e "s/[[:space:]]*$//g" -e "s/^[[:space:]]//" -e "s/ /-/g" | tr '[:upper:]' '[:lower:]' | tr -d '"' | tr -d "'"` | |
echo ${normalised_branch_component} | |
fi | |
} | |
# Function to make an initial commit for a feature branch | |
# *can* be provided with a string whch will override the text part of the commit message | |
# otherwise, it will try to parse the current feature branch name and generate from that. | |
# | |
# Expects to be on a feature branch of the form "<user>/<story_id>/branch-text-blah-blah" | |
# Grabs the next PR number by checking the most recent PR number on github and adding 1 | |
# (which may not be right if someone else creates a PR in the meantime) | |
# Returns a commit message in the form: "[#8888] [STUDIO-888] Branch text blah blah" | |
# | |
function git_initial_commit(){ | |
branch_name=`git rev-parse --symbolic-full-name --abbrev-ref HEAD` | |
if (($# == 0 )) then | |
commit_message=`echo "${branch_name}" | cut -d '-' -f3- | sed -e "s/^fe-/[FE] /" -e "s/^be/[BE] /" -e "s/-/ /g" | awk '{for (i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1'` | |
if [[ -z "${commit_message}" ]] then | |
echo "Failed to intuit the commit message; perhaps you're not on a feature branch?" | |
return 1 | |
fi | |
else | |
commit_message=$1 | |
fi | |
new_pr_id=$((`hub pr list --limit 1 --state all --format='%I%n'` + 1)) | |
story_id=`echo "${branch_name}" | awk -F '/' '{print $2}' | awk -F '-' '{print $1"-"$2}'` | |
if [ -z "$story_id" ]; then | |
echo "Story ID is empty \nDid you run this from a feature branch?" | |
return 1 | |
else | |
if [[ $story_id =~ "^ch" ]]; then | |
story_id=$(sed -e 's/ch/ch-/' <<< "${story_id}") | |
elif [[ $story_id =~ "^studio" ]]; then | |
story_id=$(tr '[:lower:]' '[:upper:]' <<< "${story_id}") | |
else | |
echo "Not sure what to do with this story ID? (${story_id})" | |
fi | |
fi | |
git add . && gc -m "[#${new_pr_id}] [${story_id}] ${commit_message}" | |
return $? | |
} | |
function git_message_prefix(){ | |
default_commit_message=`git --no-pager log --pretty=tformat:"%<(100,trunc)%s" --no-decorate -n 1 | sed -e 's/\[skip ci\].*//'` | |
PR_ID=`grep -oh '#[0-9]*' <<< "${default_commit_message}" | tr -d '#'` | |
JIRA_ID=`grep -oh 'STUDIO-[0-9]*' <<< "${default_commit_message}"` | |
echo "[#${PR_ID}] [${JIRA_ID}]" | |
} | |
# PRs are now auto-created by Github actions with an initial commit added by devops | |
# When we're ready to commit our initial work to the PR, we should remove the '[skip ci]' | |
# text and the default text and replace it with something more meaninghful: | |
# I.e. the title of the PR | |
function git_initial_commit_automation(){ | |
default_commit_message=`git --no-pager log --pretty=tformat:"%<(100,trunc)%s" --no-decorate -n 1 | sed -e 's/\[skip ci\].*//'` | |
PR_ID=`grep -oh '#[0-9]*' <<< "${default_commit_message}" | tr -d '#'` | |
JIRA_ID=`grep -oh 'STUDIO-[0-9]*' <<< "${default_commit_message}"` | |
JIRA_SUMMARY=`grep 'summary' <<< $(jv "${JIRA_ID}") | awk -F ':' '{print $2}' | sed -e 's/^[[:space:]]//'` | |
if (($# == 0 )); then | |
commit_message="${default_commit_message}${JIRA_SUMMARY}" | |
if [[ -z "${commit_message}" ]]; then | |
echo "Failed to intuit the commit message; perhaps you're not on a feature branch?" | |
return 1 | |
fi | |
FILES_CHANGED=`list_changed_files | wc -l` | |
if (( $FILES_CHANGED > 1 )); then | |
$REVOLVER_INSTALLED && revolver --style 'dots' --hide-cursor start "Changed other files, removing the temp meta file... " | |
rm -f ".meta/${JIRA_ID}.md" | |
$REVOLVER_INSTALLED && revolver stop | |
fi | |
git add . && gc --amend --no-edit -m "${commit_message}" --author="Adam Henley <[email protected]>" | |
echo "${commit_message}" | |
else | |
commit_message=$1 | |
git add . && gc -m "${default_commit_message}${commit_message}" | |
fi | |
return $? | |
} | |
function better_hub_am(){ | |
if (($# == 0 )) then | |
echo "Usage: ${0} <PR id>" | |
else | |
BASE_URL=`hub browse -u | sed -e 's/\/tree\/\(.*\)$//g'` | |
PULL_URL="${BASE_URL}/pull/${1}" | |
echo "${PULL_URL}" | |
hub am -3 "${PULL_URL}" | |
fi | |
} | |
# Given a local (repository/project-relative) path, browses to the same file on github | |
function hub_browse(){ | |
if (($# == 0 )) then | |
echo "Usage: ${0} <RELATIVE PATH TO FILE>" | |
else | |
REL_FILE_PATH=`awk -F ':' '{print $1}' <<< "${1}"` | |
LINE_NUMBERS=`awk -F ':' '{print $2}' <<< "${1}"` | |
if [[ ! -z "${LINE_NUMBERS// }" ]]; then | |
LINE_NUMBERS=`sed -e 's/[0-9]*/L&/g' <<< "${LINE_NUMBERS}"` | |
REL_FILE_PATH="${REL_FILE_PATH}#${LINE_NUMBERS}" | |
fi | |
hub browse -- "tree/$(cb)/${REL_FILE_PATH}" | |
fi | |
} | |
# WIP | |
function setup_mailgun_settings_for_review_app(){ | |
if (($# == 0 )); then | |
echo "Usage: ${0} <review-app-name>" | |
else | |
MAILGUN_API_KEY=`heroku config:get MAILGUN_API_KEY -a spielberg-api-stg`; | |
MAILGUN_DOMAIN=`heroku config:get MAILGUN_DOMAIN -a spielberg-api-stg`; | |
heroku config:set MAILGUN_API_KEY="${MAILGUN_API_KEY}" MAILGUN_DOMAIN="${MAILGUN_DOMAIN}" -a $1 | |
fi | |
} | |
function copy_matching_env_vars(){ | |
if (($# == 0 )); then | |
echo "Usage: ${0} <matching-string> <review-app-name> [dry-run]"; | |
else | |
true; | |
fi | |
} | |
# IDs of Netlify environments | |
NETLIFY_SITE_ID_STAGING='8e55f56c-f9a3-4451-899a-66eb4f704ec5' | |
NETLIFY_SITE_ID_PREVIEW='2046698f-daf7-45f3-bce6-760c35e16708' | |
NETLIFY_SITE_ID_PRODUCTION='b1f8cd82-f773-4cfe-952d-c8ff1a9a0306' | |
NETLIFY_SITE_ID_DEMO='54a0f35b-bcdb-40cd-bc64-74eef35d5c17' | |
# Diffs the environment variables set up for two Netlify environments | |
# Requires: `netlify` command line (https://docs.netlify.com/cli/get-started/) | |
# `jq` (https://stedolan.github.io/jq/) | |
# | |
# Usage: `diff_netlify_vars [--source <source> --destination <destination> --verbose]` | |
# If source is not specifed, defaults to preview | |
# If destination is not specified defaults to production | |
function diff_netlify_vars(){ | |
if ! command -v netlify &> /dev/null; then | |
echo "${ERROR} netlify not found${RESET}" | |
echo "\nInstall with 'npm install netlify-cli -g' (https://docs.netlify.com/cli/get-started/)" | |
return 1 | |
fi | |
if ! command -v jq &> /dev/null; then | |
echo "${ERROR} jq not found${RESET}" | |
echo "\nInstall with 'brew install jq' (https://stedolan.github.io/jq/)" | |
return 1 | |
fi | |
declare -A fopts | |
declare -a foptsKeys | |
fopts[--source]=$NETLIFY_SITE_ID_PREVIEW # preview | |
fopts[--destination]=$NETLIFY_SITE_ID_PRODUCTION # production | |
zparseopts -K -A fopts -- -source: -destination: -preview -production -verbose -debug | |
foptsKeys=${(k)fopts} | |
DEBUG=false | |
if [[ ${foptsKeys[(i)--debug]} -le ${#foptsKeys} ]]; then | |
DEBUG=true | |
fi | |
VERBOSE=false | |
if [[ ${foptsKeys[(i)--verbose]} -le ${#foptsKeys} ]]; then | |
VERBOSE=true | |
fi | |
if [[ ${foptsKeys[(i)--preview]} -le ${#foptsKeys} ]]; then | |
$VERBOSE && echo "Preview option given" | |
elif [[ ${foptsKeys[(i)--production]} -le ${#foptsKeys} ]]; then | |
$VERBOSE && echo "Production option given" | |
fopts[--source]=$NETLIFY_SITE_ID_PREVIEW | |
fopts[--destination]=$NETLIFY_SITE_ID_PRODUCTION | |
elif [[ ${foptsKeys[(i)--source]} -le ${#foptsKeys} ]] && [[ ${foptsKeys[(i)--destination]} -le ${#foptsKeys} ]]; then | |
$VERBOSE && echo "Source and destination set" | |
fi | |
SOURCE_API_VARIABLE='{ "site_id": "'${fopts[--source]}'" }' | |
DESTINATION_API_VARIABLE='{ "site_id": "'${fopts[--destination]}'" }' | |
$VERBOSE && echo "netlify api getSite --data ${SOURCE_API_VARIABLE}" | |
SOURCE_DATA=$(netlify api getSite --data ${SOURCE_API_VARIABLE}) | |
DESTINATION_DATA=$(netlify api getSite --data ${DESTINATION_API_VARIABLE} | tr -d '\n') | |
$DEBUG && echo $SOURCE_API_VARIABLE | |
$DEBUG && echo $SOURCE_DATA | |
$DEBUG && echo $DESTINATION_API_VARIABLE | |
$DEBUG && echo $DESTINATION_DATA | |
NETLIFY_SOURCE_NAME=$(echo -E ${SOURCE_DATA} | tr -d '\n' | jq '.name' | tr -d '"') | |
NETLIFY_DESTINATION_NAME=$(echo -E ${DESTINATION_DATA} | tr -d '\n' | jq '.name' | tr -d '"') | |
NETLIFY_SOURCE_ENV_VARS=$(echo -E $SOURCE_DATA | tr -d '\n' | jq '.build_settings.env | keys' | tr -d '",][' | sed '/^$/d') | |
NETLIFY_DESTINATION_ENV_VARS=$(echo -E $DESTINATION_DATA | tr -d '\n' | jq '.build_settings.env | keys' | tr -d '",][' | sed '/^$/d') | |
$VERBOSE && $REVOLVER_INSTALLED && revolver --style 'dots' --hide-cursor start "Comparing... " | |
$VERBOSE && echo "Source: \t${NETLIFY_SOURCE_NAME} \t(${fopts[--source]})" | |
$VERBOSE && echo "Destination: \t${NETLIFY_DESTINATION_NAME} \t(${fopts[--destination]}\n" | |
NETLIFY_DIFF_RESULTS=`diff <(echo ${NETLIFY_SOURCE_ENV_VARS}) <(echo ${NETLIFY_DESTINATION_ENV_VARS}) | grep '<' | awk '{print $2}' | tr -d ':'` | |
$VERBOSE && $REVOLVER_INSTALLED && revolver stop | |
NETLIFY_DIFF_LINE_COUNT=`echo $NETLIFY_DIFF_RESULTS | tr -d "\n" | wc -l` | |
if [[ "$NETLIFY_DIFF_LINE_COUNT" -eq "0" ]]; then | |
$VERBOSE && echo "${WARNING}Did not find any differences between the two sets of ENV VARS?${RESET}" | |
$VERBOSE && echo "Source: \n${NETLIFY_SOURCE_ENV_VARS}" | |
$VERBOSE && echo "Destination: \n${NETLIFY_DESTINATION_ENV_VARS}" | |
else | |
$VERBOSE && echo "Check if the following ENV vars are needed on ${GREEN}${fopts[--destination]}${RESET} before release:" | |
echo $NETLIFY_DIFF_RESULTS | awk '{print "\t",$0}' | |
fi | |
} | |
# Diffs the environment variables set up for two Heroku environments | |
# Requires: the `heroku` command line to be installed | |
# (https://devcenter.heroku.com/articles/heroku-cli) | |
# | |
# Nice-to-have: `revolver` (https://github.com/adamazing/revolver) | |
# | |
# Usage: `diff_heroku_env_vars [--source <source> --destination <destination> -production --verbose]` | |
# If source is not specifed, defaults to preview | |
# If destination is not specified defaults to production | |
function diff_heroku_env_vars(){ | |
if ! command -v heroku &> /dev/null; then | |
echo "${ERROR} heroku not found${RESET}" | |
echo "\nInstall with 'brew tap heroku/brew && brew install heroku' (https://devcenter.heroku.com/articles/heroku-cli)" | |
return 1 | |
fi | |
declare -A fopts | |
declare -a foptsKeys | |
fopts[--source]="spielberg-api-pre" # preview | |
fopts[--destination]="spielberg-api" # production | |
zparseopts -K -A fopts -- -source: -destination: -production -verbose | |
foptsKeys=${(k)fopts} | |
VERBOSE=false | |
if [[ ${foptsKeys[(i)--verbose]} -le ${#foptsKeys} ]]; then | |
VERBOSE=true | |
fi | |
if [[ ${foptsKeys[(i)--production]} -le ${#foptsKeys} ]]; then | |
$VERBOSE && echo "Production option given" | |
fopts[--source]="spielberg-api-pre" | |
fopts[--destination]="spielberg-api" | |
elif [[ ${foptsKeys[(i)--source]} -le ${#foptsKeys} ]] && [[ ${foptsKeys[(i)--destination]} -le ${#foptsKeys} ]]; then | |
$VERBOSE && echo "Source and destination set" | |
fi | |
$VERBOSE && $REVOLVER_INSTALLED && revolver --style 'dots' --hide-cursor start "Comparing... " | |
$VERBOSE && echo "Source: \t${fopts[--source]}" | |
$VERBOSE && echo "Destination: \t${fopts[--destination]}\n" | |
HEROKU_DIFF_RESULTS=`diff <(heroku config --app ${fopts[--source]} | awk '{print $1}') <(heroku config --app ${fopts[--destination]} | awk '{print $1}') | grep '<' | awk '{print $2}' | tr -d ':'` | |
$VERBOSE && $REVOLVER_INSTALLED && revolver stop | |
$VERBOSE && echo "Check if the following ENV vars are needed on ${GREEN}${fopts[--destination]}${RESET} before release:" | |
echo $HEROKU_DIFF_RESULTS | awk '{print "\t",$0}' | |
} | |
function pr_in_branch(){ | |
OLD_BRANCH=`cb` | |
declare -A fopts | |
declare -a foptsKeys | |
# Set default values | |
fopts[--pr]=1111 # current PR id | |
fopts[--branch]="preview" | |
zparseopts -K -A fopts -- -pr: -branch: | |
foptsKeys=${(k)fopts} | |
MERGE_SHA=`hub api /repos/{owner}/{repo}/pulls/${fopts[--pr]} -t | grep "merge_commit_sha" | awk '{print $2}'` | |
RETURN=`gbc $MERGE_SHA 2>/dev/null | grep ${fopts[--branch]}` | |
if [[ $RETURN ]]; then | |
echo "${SUCCESS}PR ${fopts[--pr]} ($MERGE_SHA) found in branch ${fopts[--branch]}" | |
return 0; | |
else | |
echo "${ERROR}PR ${fopts[--pr]} ($MERGE_SHA) NOT found in branch ${fopts[--branch]}${RESET}" | |
echo "\nIs ${fopts[--branch]} up to date?" | |
return 1; | |
fi | |
} | |
# Delete others' branches | |
# Keeps $BRANCH_USER's branches, develop, preview, master, and sr-devops' branches | |
function delete_others_branches(){ | |
ON_A_BRANCH_WHICH_WILL_BE_DELETED=`cb | grep -E "^(${BRANCH_USER}|develop|master|preview|sr-devops)"` | |
if [ ! $ON_A_BRANCH_WHICH_WILL_BE_DELETED ]; then | |
git checkout develop | |
fi | |
git for-each-ref --format="%(refname:short)" refs/heads/ | \ | |
grep -v -E -e "^${BRANCH_USER}" -e "^develop" -e "^master" -e "^preview" -e "^sr-devops" | xargs git branch -D | |
} | |
# Get a list of all branches matching a particular pattern and list them preceded | |
# with an index number. | |
# | |
# The pattern used to search is saved in a variable (BRANCH_PATTERN_STRING) which is | |
# re-used by switch/delete functions | |
function grep_branches(){ | |
typeset -g BRANCH_PATTERN_STRING | |
if (($# == 0 )) then | |
BRANCH_PATTERN_STRING='.\\*' | |
else | |
BRANCH_PATTERN_STRING=$1 | |
fi | |
declare -A fopts | |
declare -a foptsKeys | |
# Set default values | |
fopts[-p]=false # with PR numbers | |
zparseopts -K -A fopts -- -p: | |
foptsKeys=${(k)fopts} | |
array_of_lines=("${(@f)$(gb | grep ${BRANCH_PATTERN_STRING})}") | |
if [[ (( $#array_of_lines == 0 )) || -z "${array_of_lines[1]// }" ]]; then | |
echo "No branches matching \"${BRANCH_PATTERN_STRING}\" were found" | |
return 1 | |
fi | |
if [[ ${foptsKeys[(i)-p]} -le ${#foptsKeys} ]]; then | |
array_of_gh_prs=("${(@f)$(unbuffer hub pr list -f "%pC%i%Creset %H %n" --color | grep ${BRANCH_PATTERN_STRING})}") | |
for ((i = 1; i <= $#array_of_lines; i++)); do | |
for ((j = 1; j <= $#array_of_gh_prs; j++)); do | |
if [[ "${${array_of_gh_prs[$j]}##*"${array_of_lines[$i]}"*}" ]]; then | |
# echo "${j}th PR ARRAY ITEM: \t ${array_of_gh_prs[$j]}" | |
# echo "${i}th LINE ARRAY ITEM: \t ${array_of_lines[$i]}" | |
true | |
else | |
array_of_lines[i]="${array_of_gh_prs[$j]}" | |
break | |
fi | |
done | |
done | |
fi | |
for ((ii = 1; ii <= $#array_of_lines; ii++)); do | |
echo "[$ii] \t ${array_of_lines[$ii]}" | |
done | |
} | |
# My branches | |
function mb(){ | |
grep_branches "${BRANCH_USER}" -p | |
} | |
# Epic branches | |
function eb(){ | |
grep_branches "sr-devops" -p | |
} | |
# Switch to a branch at an index determined earlier by running `grep_branches`, or a | |
# function/alias that calls it. | |
# E.g. | |
# $ grep_branches ^adam | |
# [1] adamhenley/ch123455/my-cool-task-number-1 | |
# [2] adamhenley/ch543211/my-other-cool-task-branch | |
# | |
# $ sb 1 | |
# Using previously set value for branch pattern: ^adam | |
# remote: Enumerating objects: 1, done. | |
# remote: Counting objects: 100% (1/1), done. | |
# remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 | |
# Unpacking objects: 100% (1/1), done. | |
# .... <Checks out branch 'adamhenley/ch123455/my-cool-task-number-1'> .... | |
function switch_to_nth_branch(){ | |
if (($# == 0 )) then | |
echo "Usage: ${0} <NUMBER> [<BRANCH>]" | |
else | |
N=$1 | |
if [[ ! -z "${2// }" ]]; then | |
BRANCH_PATTERN_STRING=$2 | |
else | |
if [[ -z "${BRANCH_PATTERN_STRING// }" ]]; then | |
BRANCH_PATTERN_STRING="^${BRANCH_USER}" | |
else | |
echo "Using previously set value for branch pattern: ${BRANCH_PATTERN_STRING}" | |
fi | |
fi | |
array_of_lines=("${(@f)$(gb | grep ${BRANCH_PATTERN_STRING})}") | |
if [[ ! -z "${array_of_lines[${N}]// }" ]]; then | |
git checkout "${array_of_lines[${N}]// }" | |
else | |
echo "Branch not found." | |
echo "" | |
grep_branches ${BRANCH_PATTERN_STRING} | |
fi | |
BRANCH_PATTERN_STRING='' | |
fi | |
} | |
# Function takes a number and optionally branch pattern to match, finds matching local branches and deletes them, without | |
# any regard to whether they have been merged. Use with caution. Works like above `switch_to_nth_branch` function | |
# except it deletes the branch instead of switching to it. | |
function gbndt(){ | |
if (($# == 0 )) then | |
echo "Usage: ${0} <NUMBER> [<BRANCH>]" | |
else | |
N=$1 | |
if [[ ! -z "${2// }" ]]; then | |
BRANCH_PATTERN_STRING=$2 | |
else | |
if [[ -z "${BRANCH_PATTERN_STRING// }" ]]; then | |
echo "${ERROR} No branch pattern set, aborting.${RESET}" | |
return 1 | |
else | |
echo "Using previously set value for branch pattern: ${BRANCH_PATTERN_STRING}" | |
fi | |
fi | |
array_of_lines=("${(@f)$(gb | grep ${BRANCH_PATTERN_STRING})}") | |
if [[ ! -z "${array_of_lines[${N}]// }" ]]; then | |
if [ "${array_of_lines[${N}]// }" = "$(cb)" ]; then | |
git checkout develop | |
fi | |
git branch -D ${array_of_lines[${N}]} | |
else | |
echo "${WARNING}Branch not found.${RESET}"x | |
fi | |
echo "" | |
grep_branches ${BRANCH_PATTERN_STRING} | |
fi | |
} | |
# function pr_to_ch(){ | |
# hub api /repos/{owner}/{repo}/pulls/$1 --flat | grep ".body" | awk -F '\t' '{print $2}' | grep -o 'clubhouse\.io.*story\/[0-9]*' | awk -F '/' '{print $NF}' | |
# } | |
# Custom colours for `jq` JSON pretty printer (Install: `brew install jq`) | |
# export JQ_COLORS="1;30:0;31:0;32:1;35:1;37:1;36:1;33" | |
# general shell env variables | |
export GPG_TTY=$(tty) | |
export LEFTHOOK=0 | |
export EDITOR='nvim' | |
export VISUAL='nvim' | |
export DISABLE_SPRING=1 | |
export DYNO='foo' | |
export JIRA_EDITOR='nvim' | |
# export AWS_DEFAULT_PROFILE='PowerUserAccess-522918171347' | |
#nodenv | |
eval "$(nodenv init -)" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Ansi 0 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.162628173828125</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.12134135514497757</real> | |
<key>Red Component</key> | |
<real>0.065521761775016785</real> | |
</dict> | |
<key>Ansi 1 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.21094882488250732</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.22206461429595947</real> | |
<key>Red Component</key> | |
<real>0.851959228515625</real> | |
</dict> | |
<key>Ansi 10 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.45882353186607361</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.43137255311012268</real> | |
<key>Red Component</key> | |
<real>0.34509804844856262</real> | |
</dict> | |
<key>Ansi 11 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.51372551918029785</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.48235294222831726</real> | |
<key>Red Component</key> | |
<real>0.3960784375667572</real> | |
</dict> | |
<key>Ansi 12 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.58823531866073608</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.58039218187332153</real> | |
<key>Red Component</key> | |
<real>0.51372551918029785</real> | |
</dict> | |
<key>Ansi 13 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.76862746477127075</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.44313725829124451</real> | |
<key>Red Component</key> | |
<real>0.42352941632270813</real> | |
</dict> | |
<key>Ansi 14 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.63137257099151611</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.63137257099151611</real> | |
<key>Red Component</key> | |
<real>0.57647061347961426</real> | |
</dict> | |
<key>Ansi 15 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.89019608497619629</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.96470588445663452</real> | |
<key>Red Component</key> | |
<real>0.99215686321258545</real> | |
</dict> | |
<key>Ansi 2 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.27256298065185547</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.84344482421875</real> | |
<key>Red Component</key> | |
<real>0.26041048765182495</real> | |
</dict> | |
<key>Ansi 3 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.25379422307014465</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.79675358533859253</real> | |
<key>Red Component</key> | |
<real>0.876556396484375</real> | |
</dict> | |
<key>Ansi 4 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.82352942228317261</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.54509806632995605</real> | |
<key>Red Component</key> | |
<real>0.14901961386203766</real> | |
</dict> | |
<key>Ansi 5 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.50980395078659058</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.21176470816135406</real> | |
<key>Red Component</key> | |
<real>0.82745099067687988</real> | |
</dict> | |
<key>Ansi 6 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.59607845544815063</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.63137257099151611</real> | |
<key>Red Component</key> | |
<real>0.16470588743686676</real> | |
</dict> | |
<key>Ansi 7 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.8723297119140625</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.96935915946960449</real> | |
<key>Red Component</key> | |
<real>1</real> | |
</dict> | |
<key>Ansi 8 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.21176470816135406</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.16862745583057404</real> | |
<key>Red Component</key> | |
<real>0.0</real> | |
</dict> | |
<key>Ansi 9 Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.086274512112140656</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.29411765933036804</real> | |
<key>Red Component</key> | |
<real>0.79607844352722168</real> | |
</dict> | |
<key>Background Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.21176470816135406</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.16862745583057404</real> | |
<key>Red Component</key> | |
<real>0.0</real> | |
</dict> | |
<key>Badge Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>0.5</real> | |
<key>Blue Component</key> | |
<real>0.0</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.1491314172744751</real> | |
<key>Red Component</key> | |
<real>1</real> | |
</dict> | |
<key>Bold Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.63137257099151611</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.63137257099151611</real> | |
<key>Red Component</key> | |
<real>0.57647061347961426</real> | |
</dict> | |
<key>Cursor Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.58823531866073608</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.58039218187332153</real> | |
<key>Red Component</key> | |
<real>0.51372551918029785</real> | |
</dict> | |
<key>Cursor Guide Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>0.25</real> | |
<key>Blue Component</key> | |
<real>1</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.9268307089805603</real> | |
<key>Red Component</key> | |
<real>0.70213186740875244</real> | |
</dict> | |
<key>Cursor Text Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.1031285896897316</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.1031285896897316</real> | |
<key>Red Component</key> | |
<real>0.29864501953125</real> | |
</dict> | |
<key>Foreground Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.936309814453125</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.92887908220291138</real> | |
<key>Red Component</key> | |
<real>0.86571794748306274</real> | |
</dict> | |
<key>Link Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.73423302173614502</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.35916060209274292</real> | |
<key>Red Component</key> | |
<real>0.0</real> | |
</dict> | |
<key>Selected Text Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.63137257099151611</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.63137257099151611</real> | |
<key>Red Component</key> | |
<real>0.57647061347961426</real> | |
</dict> | |
<key>Selection Color</key> | |
<dict> | |
<key>Alpha Component</key> | |
<real>1</real> | |
<key>Blue Component</key> | |
<real>0.25882354378700256</real> | |
<key>Color Space</key> | |
<string>sRGB</string> | |
<key>Green Component</key> | |
<real>0.21176470816135406</real> | |
<key>Red Component</key> | |
<real>0.027450980618596077</real> | |
</dict> | |
</dict> | |
</plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# If you put environment variables in your zshrc, add a line containing 'REDACT' | |
# above them all. This function will copy it to your clipboard, redacting everything | |
# below that line. | |
function export_zshrc(){ | |
sed -e '/REDACT/,$d' ~/.zshrc | pbcopy | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
RED="\033[1;31m" | |
ERROR=$RED | |
GREEN="\033[1;32m" | |
SUCCESS=$GREEN | |
ORANGE="\033[1;33m" | |
WARNING=$ORANGE | |
WHITE="\033[0;37m" | |
RESET="\033[0m" | |
if command -v revolver &> /dev/null; then | |
REVOLVER=true | |
else | |
REVOLVER=false | |
fi | |
AUDIT_RESULTS_FILE="audit.md" | |
GH_ORGANISATION="Shuttlerock" | |
GH_BASE_URL="[email protected]:" | |
SUCCESS_DIR="success" | |
FAILURE_DIR="faaail" | |
mkdir -p ${SUCCESS_DIR} | |
mkdir -p ${FAILURE_DIR} | |
while IFS=',' read -r f1 f2 f3 f4 f5 f6 || [ -n "${LINE}" ]; do | |
REPOSITORY_NAME=${f1} | |
REPOSITORY_URL="${GH_BASE_URL}${GH_ORGANISATION}/${REPOSITORY_NAME}.git" | |
if [[ ! "${f5// }" == "TRUE" ]]; then | |
echo "Auditing repository: ${WHITE}${REPOSITORY_NAME}${RESET}" | |
echo " Checking out repository from: ${REPOSITORY_URL}" | |
$REVOLVER && revolver --style 'dots' --hide-cursor start | |
git clone ${REPOSITORY_URL} --no-progress | |
$REVOLVER && revolver stop | |
LAST_EXIT_CODE=$? | |
if [[ $LAST_EXIT_CODE -ne 0 ]]; then | |
echo " ${ERROR}Checkout failed${RESET}" | |
echo "*⚠️ ${REPOSITORY_NAME} could not be checked out?*" >> ./${AUDIT_RESULTS_FILE} | |
else | |
echo " Scanning repository: ${REPOSITORY_NAME}" | |
$REVOLVER && revolver --style 'dots' --hide-cursor start | |
gitleaks --repo-path=${REPOSITORY_NAME} --verbose --pretty > ${REPOSITORY_NAME}.txt | |
GITLEAKS_EXIT_CODE=$? | |
$REVOLVER && revolver stop | |
# 0: no leaks | |
# 1: leaks present | |
# 2: error encountered | |
if [[ $GITLEAKS_EXIT_CODE -eq 0 ]]; then | |
echo " ${SUCCESS}✔️ No leaks found for ${REPOSITORY_NAME}${RESET}" | |
echo "✔️ ${REPOSITORY_NAME} is clean" >> ./${AUDIT_RESULTS_FILE} | |
mv ./${REPOSITORY_NAME} ./${REPOSITORY_NAME}.txt ./${SUCCESS_DIR} | |
elif [[ $GITLEAKS_EXIT_CODE -eq 1 ]]; then | |
echo " ${WARNING}⚠️ Leaks found for ${REPOSITORY_NAME}${RESET}" | |
echo "*⚠️ ${REPOSITORY_NAME} has leaks*" >> ./${AUDIT_RESULTS_FILE} | |
mv ./${REPOSITORY_NAME} ./${REPOSITORY_NAME}.txt ./${FAILURE_DIR} | |
else | |
echo " ${ERROR}Error occurred while scanning ${REPOSITORY_NAME}${RESET}" | |
echo "*⚠️ ${REPOSITORY_NAME} errored while scanning*" >> ./${AUDIT_RESULTS_FILE} | |
fi | |
fi | |
fi | |
done < $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment