Skip to content

Instantly share code, notes, and snippets.

@erichiller
Last active May 23, 2024 04:52
Show Gist options
  • Save erichiller/ac3be5b4a562a61b255b0baccb3f2da8 to your computer and use it in GitHub Desktop.
Save erichiller/ac3be5b4a562a61b255b0baccb3f2da8 to your computer and use it in GitHub Desktop.
# ERIC - EDH - setup bash
# If not running interactively, don't do anything
# this keeps SCP (file transfer from throwing errors) -- stops here
case $- in
*i*) ;;
*) return;;
esac
# Prevent Loops
if [ -z $NO_LOOPS ]; then NO_LOOPS=true; else unset NO_LOOPS; return; fi
#Golang
if [ -d "/c/Go" ] ; then
export GOROOT=/c/go
export GOPATH=~/dev
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
elif [ -d "$HOME/dev/lib/go" ] ; then
export GOROOT=~/dev/lib/go
export GOPATH=~/dev
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
fi
# BASH History with Date Timestamp
HISTTIMEFORMAT="%F %T "
HISTFILESIZE=10000
# for less / man coloring
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# for terminal line coloring
if [ "$IS_WSL" ]; then
# do not display the user if in Windows Subsystem for Linux, I find it useless
export PS1="\[$(tput sgr0)\]\[$(tput setaf 6)\]\h \[$(tput setaf 5)\]\w \[$(tput setaf 1)\]\\$ \[$(tput setaf 2)\]"
else
export PS1="\[$(tput sgr0)\]\[$(tput setaf 4)\]\u@\[$(tput setaf 6)\]\h \[$(tput setaf 5)\]\w \[$(tput setaf 1)\]\\$ \[$(tput setaf 2)\]"
fi
# Reset terminal coloration
RESET="$(tput sgr0)"
# Change the terminal title to the currently executing command
trap 'echo -ne "\033]2;$(history 1 | sed -E "s/^[ ]*([0-9\:\-]+[ ]+){1,3}//g")\007${RESET}"' DEBUG
# Shorten directory path in \w
export PROMPT_DIRTRIM=3
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*|cygwin)
export PS1="\[\e]0;\u@\h: \w\a\]$PS1"
export SETTITLE="YES"
;;
*)
;;
esac
# ls dir coloring
export LS_OPTIONS='--color=auto'
eval "`dircolors -b`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -la'
alias pathprint='echo $PATH | tr \: \\n'
# for grep coloring
alias grep='grep --color=always'
alias less='less -R'
# alias vim if we are on ConEmu
if [ -f $ConEmuDir/config/.vimrc ] ; then
alias vi='vim -u $ConEmuDir/config/.vimrc'
alias vim='vim -u $ConEmuDir/config/.vimrc'
fi
# now read input rc
if [ -f ${ConEmuDir}/config/inputrc ] ; then bind -f ${ConEmuDir}/config/inputrc ; fi
# search history by start of the current line
bind '"\eOA": history-search-backward'
bind '"\e[A": history-search-backward'
bind '"\eOB": history-search-forward'
bind '"\e[B": history-search-forward'
# Double ESC to kill the ENTIRE line (windows like)
bind '"\e\e":kill-whole-line'
# Ctrl + Backspace to delete last word
bind '"\C-H": shell-backward-kill-word'
# set ^h (0x08, aka True Backspace) to the erase character
stty sane
# Immediately appends commands to the bash history
PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
# Select line and paste to keyboard ; can make use of MARK and POINT for regional selection
select_all (){
if [[ $READLINE_LINE == "" ]]; then
return;
fi;
start=$(($READLINE_MARK+1));
end=$READLINE_POINT;
echo -n $READLINE_LINE | cut -z -c $start-$end | xsel -b
}
bind -x '"\C-x": select_all'
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
# if completions do not work, try installing with: sudo apt install bash-completion
fi
if [ -f ~/.arduino15/bash_completion.sh ]; then
. ~/.arduino15/bash_completion.sh
fi
# see startup sequence : https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
# if this is global read user files, if it is local, I am done.
# sometimes this file is used as .bashrc, sometimes it isn't, let's keep it from causing infinite loops
# (it's happened, it wasn't fun)
#if [ `basename "$BASH_SOURCE"` != ".profile" ] && [ -f ~/.profile ]; then . ~/.profile; fi
#if [ `basename "$BASH_SOURCE"` != ".bashrc" ] && [ -f ~/.bashrc ]; then . ~/.bashrc; fi
export DOCKER_HOST=ssh://user@docker
export LOKI_ADDR=http://docker:3100
#PATH="$HOME/.local/bin/mkmrk:$HOME/.dotnet/tools:$PATH"
export DOTNET_ROOT=/usr/share/dotnet/
# PSQL (PostgreSQL Client)
export PGHOST="pg.domain.tld"
export PGSSLMODE="verify-full"
#export PGSSLCERT="chain.cert.pem"
#export PGSSLKEY="key.pem"
#export PGSSLROOTCERT="CA.cert.pem"
export PGSSLMINPROTOCOLVERSION="TLSv1.3"
export PGDATABASE="my-db"
export PGAPPNAME="psql@$HOSTNAME"
#### END PSQL
# .clang-format
# Eric D. Hiller
# 2018 February 12
# reference:
# <http://clang.llvm.org/docs/ClangFormatStyleOptions.html>
# To convert to a Value: 'quoted' format
# which is required for https://zed0.co.uk/clang-format-configurator/
# use the regex search: \n(?=\n{1,2}[#A-Za-z])
# and replace with '\n
# view a default styled config with
# clang-format -style=WebKit -dump-config
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
# only if BreakBeforeBraces is set to Custom
BraceWrapping:
# AfterClass: false
# AfterControlStatement: true
# AfterEnum: false
# AfterFunction: true
# AfterNamespace: false
# AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
# AfterExternBlock: false
# BeforeCatch: false
# BeforeElse: true
# IndentBraces: false
# SplitEmptyFunction: true
# SplitEmptyRecord: true
# SplitEmptyNamespace: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: false
# See if vscode will inject its config here
# ideally I want unlimited (config of 0)
ColumnLimit: 0
CompactNamespaces: false
# I'd rather have one parameter per line
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
# may or may not work
# ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IncludeBlocks: Regroup
# I don't think I need to set this, it pertains to include blocks
# IncludeCategories
IndentCaseLabels: true
# The preprocessor directive indenting style to use.
# Options: None //or// AfterHash
IndentPPDirectives: None
# try leaving blank, vscode defaults
IndentWidth: 4
IndentWrappedFunctionNames: true
JavaScriptQuotes: Double
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
# set language Target, optional
# I'd say don't, but it could be
# Language Cpp
MaxEmptyLinesToKeep: 5
NamespaceIndentation: Inner
# see penalty* configs
# leaving unconfigured for now
PointerAlignment: Right
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
# try at least , not 100% sold
SpaceInEmptyParentheses: true
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: false
Standard: Cpp11
# It did not inherit vscode's settings
TabWidth: 4
# It did not inherit vscode's settings
# ForIndentation //or// Always
UseTab: ForIndentation
# ~/.inputrc
# https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html
# https://www.gnu.org/software/bash/manual/html_node/Sample-Init-File.html#Sample-Init-File
set colored-completion-prefix on
set colored-stats on
set completion-ignore-case on
set expand-tilde on
set print-completions-horizontally on
set skip-completed-text
set revert-all-at-newline on
" Setting some decent VIM settings for programming
set showmatch " automatically show matching brackets. works like it does in bbedit.
set vb " turn on the "visual bell" - which is much quieter than the "audio blink"
set ruler " show the cursor position all the time
set laststatus=2 " make the last line (status) two lines deep so you can always see status
set backspace=indent,eol,start " make that backspace key work the way it should
set nocompatible " vi compatible is LAME
set background=dark " Use colours that work well on a dark background (Console is usually black)
set showmode " show the current mode
syntax on " turn syntax highlighting on by default
set hlsearch " highlight search terms
" EDH ---- force tabs, not spaces ----
colorscheme desert " good general purpose colorscheme
set autoindent " set auto-indenting on for programming; filetype plugin should
" override this for smartindent / cindent depending on filetype
" see: http://vim.wikia.com/wiki/Indenting_source_code
set noexpandtab
set tabstop=4 " EDH - standard 4 space=tab
set shiftwidth=4 " Number of spaces to use for each step of (auto)indent.
filetype plugin indent on " Enable file type detection. to automatically do language-dependent indenting.
set number " Show line numbers.
set history=150 " keep 50 lines of command line history
set showcmd " display incomplete commands
set incsearch " do incremental searching
" Show EOL type and last modified timestamp, right after the filename
set statusline=%<%F%h%m%r\ %y\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))})%=%l,%c%V\ %P
" Set up .md as markdown as well
au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown
"------------------------------------------------------------------------------
" Only do this part when compiled with support for autocommands.
if has("autocmd")
"Set UTF-8 as the default encoding for commit messages
autocmd BufReadPre COMMIT_EDITMSG,git-rebase-todo setlocal fileencodings=utf-8
"Remember the positions in files with some git-specific exceptions"
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$")
\ && expand("%") !~ "COMMIT_EDITMSG"
\ && expand("%") !~ "ADD_EDIT.patch"
\ && expand("%") !~ "addp-hunk-edit.diff"
\ && expand("%") !~ "git-rebase-todo" |
\ exe "normal g`\"" |
\ endif
autocmd BufNewFile,BufRead *.patch set filetype=diff
autocmd BufNewFile,BufRead *.diff set filetype=diff
autocmd Syntax diff
\ highlight WhiteSpaceEOL ctermbg=red |
\ match WhiteSpaceEOL /\(^+.*\)\@<=\s\+$/
autocmd Syntax gitcommit setlocal textwidth=74
endif " has("autocmd")
#!/bin/bash
# Run this script with:
# wget --quiet -O - bashrc.hiller.pro | bash
set -x
sudo apt update && sudo apt upgrade -y && sudo apt install -y vim wget unzip gpg bind9-dnsutils bash-completion lsof xsel
# command -v vim >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
GIST_HOST="https://gist.github.com";
GIST_BASE_URL="$GIST_HOST/erichiller/ac3be5b4a562a61b255b0baccb3f2da8";
GIST_ZIP_URL="$GIST_HOST`curl $GIST_BASE_URL --silent | grep '(?<=href=")[^"]*(?=">Download ZIP)' -Po`"
pushd /tmp
wget $GIST_ZIP_URL --output-document=settings.zip
unzip -j settings.zip
mv .bashrc ~/.edh.bashrc
mv .vimrc ~
mv .inputrc ~
echo ". ~/.edh.bashrc" >> ~/.bashrc
echo "UPDATE ANY NECESSARY SETTINGS IN ~/.edh.bashrc"
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment