1
0
Fork 0

Updated bash configs

This commit is contained in:
Gregory Eremin 2020-09-12 09:58:04 +02:00
parent a3df3a425f
commit 1c2c69c6b2
16 changed files with 162 additions and 166 deletions

2
.gitignore vendored
View File

@ -9,4 +9,4 @@ fish/nginx.conf
git/git-achievements*
git.pgp
bash/secrets.bash
bash/secrets/*

View File

@ -1,11 +1,8 @@
# General
alias ll="ls -lAFh"
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
alias ll="ls -lAFh --color"
alias dedup="awk '!visited[$0]++'"
# Git
alias git="git-achievements"
alias ga="git add -u; git add .; git status -sb"
alias gb="git branch -v"
alias gc="git ci --allow-empty -m"
@ -20,16 +17,11 @@ alias gcl="git co -"
alias gml="git merge - --no-edit"
# Ruby
alias bd="bundle install --jobs=8 --path vendor/bundle"
alias bd="bundle install --jobs=8"
alias bdc="bundle config set path 'vendor/bundle'"
alias b="bundle exec"
alias br="bundle exec rails"
# Go
alias goi="go install ./..."
alias gg='rg -g "*.go"'
# OSX
alias hide-desktop="defaults write com.apple.finder CreateDesktop -bool false; killall Finder"
alias show-desktop="defaults write com.apple.finder CreateDesktop -bool true; killall Finder"
alias prefs="/Applications/System\ Preferences.app/Contents/MacOS/System\ Preferences"
alias admin-prefs="sudo /Applications/System\ Preferences.app/Contents/MacOS/System\ Preferences"

View File

@ -1,49 +0,0 @@
# Enable debug
# set -xv
export TERM=xterm-256color
export EDITOR=vim
# Colors
export CLICOLOR=1
export LSCOLORS=Exfxcxdxbxegedabagacad
export EDITOR=vim
export PROJECTS=$HOME/Code
# Go
# export GOROOT=$HOME/go/lang
export GOPATH=$HOME/go/path
function __bash_import { source $HOME/.bash/$1.bash; }
__bash_import "functions_internal"
__bash_import "history"
__bash_import "path"
__bash_import "format"
__bash_import "iterm"
__bash_import "alias"
__bash_import "prompt"
__bash_import "functions"
__bash_import "gover"
__bash_import "docker"
__bash_import "secrets"
# Homebrew bash completions
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
#
# Misc
#
alias ag=rg
# export SSL_CERT_FILE="/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt"
export PATH="/usr/local/opt/avr-gcc@8/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
export PATH="$HOME/.cargo/bin:$PATH"

47
bash/bashrc.sh Normal file
View File

@ -0,0 +1,47 @@
# Enable debug
# set -xv
source /etc/profile
export TERM=xterm-256color
export EDITOR=vim
# Colors
export CLICOLOR=1
export LSCOLORS=Exfxcxdxbxegedabagacad
export EDITOR=vim
export PROJECTS=$HOME/Code
# Go
# GOROOT can be easily derived from go binary path
# export GOROOT=$HOME/go/lang
export GOPATH=$HOME/go/path
source $HOME/dotfiles/bash/functions_internal.sh
source $HOME/dotfiles/bash/history.sh
source $HOME/dotfiles/bash/path.sh
source $HOME/dotfiles/bash/format.sh
source $HOME/dotfiles/bash/alias.sh
source $HOME/dotfiles/bash/prompt.sh
source $HOME/dotfiles/bash/functions.sh
source $HOME/dotfiles/bash/overrides.sh
for f in $HOME/dotfiles/bash/{tools,secrets}/*; do
source $f
done
# Use bash-completion, if available
[[ $PS2 && -f /usr/share/bash-completion/bash_completion ]] && \
. /usr/share/bash-completion/bash_completion
#
# Misc
#
export PATH="$HOME/.local/bin:$PATH"
# Disable Ruby 2.7 deprecation warnings
# export RUBYOPT='-W:no-deprecated -W:no-experimental'
export RUBYOPT=

View File

@ -1,17 +0,0 @@
function d-ssh {
docker exec -it $1 /bin/bash
}
function _d-ssh {
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -o nospace -W "$(docker ps -a --format '{{.Names}}')" -- $cur))
}
complete -F _d-ssh d-ssh
function d-ps {
docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Status}}\t{{.CreatedAt}}" $@
}
function d-clean {
local images=$(docker images -a | grep -e '^<none>' | awk '{print $3}' | cut -d: -f2)
[[ -n $images ]] && docker rmi -f $images
}

View File

@ -7,17 +7,17 @@ _DIM=$(__bash_escape 2)
_ITALIC=$(__bash_escape 3)
_UNDERLINED=$(__bash_escape 4)
_BLINK=$(__bash_escape 5)
# _BRIGHT=$(__bash_escape 6)
_BRIGHT=$(__bash_escape 6)
_INVERTED=$(__bash_escape 7)
_HIDDEN=$(__bash_escape 8) # E.g. for passwords
_RESET=$(__bash_escape 0)
_RESET_BOLD=$(__bash_escape 21) # Doesn't work?
_RESET_BOLD=$(__bash_escape 21)
_RESET_DIM=$(__bash_escape 22)
_RESET_ITALIC=$(__bash_escape 23)
_RESET_UNDERLINED=$(__bash_escape 24)
_RESET_BLINK=$(__bash_escape 25)
# _RESET_BRIGHT=$(__bash_escape 26)
_RESET_BRIGHT=$(__bash_escape 26)
_RESET_INVERTED=$(__bash_escape 27)
_RESET_HIDDEN=$(__bash_escape 28)

View File

@ -1,18 +1,8 @@
function reload {
source $HOME/.bash_profile
}
function ssh {
# Change tab title
local host=$(echo $1 | cut -d@ -f1)
__iterm_set_title $host
# Change tab color and reset back when conneciton is closed
__iterm_set_bg_rgb 220 20 0 && \
/usr/bin/ssh $@ && \
__iterm_set_bg_reset
source $HOME/.bashrc
}
# Count lines of code in files that are checked into the current Git repository
function gkloc {
cloc $(git ls-files)
}
@ -23,6 +13,10 @@ function shuf {
cut -d' ' -f2-
}
function __window_title {
echo -ne "\033]0;$1\007"
}
function __bash_ssh_complete {
__bash_complete "$(cat $HOME/.ssh/known_hosts | cut -d' ' -f1 | cut -d, -f1)"
}
@ -42,7 +36,7 @@ complete -F _c c
function cg { cd $GOPATH/src/github.com/$1; }
function _cg { __bash_directory_complete $GOPATH/src/github.com; }
complete -F _cg cg
complete -W "$(dir -d $HOME/go/path/src/github.com/*/* | cut -d'/' -f8-)" cg
#
# Misc
@ -53,6 +47,5 @@ function __bash_directory_complete {
}
function __bash_complete {
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -o nospace -W "$1" -- $cur))
COMPREPLY=($(compgen -o nospace -W "$1" -- ${COMP_WORDS[COMP_CWORD]}))
}

View File

@ -1,31 +0,0 @@
# $1 - title
function __iterm_set_title {
echo -ne "\033]0;$1\007"
}
# $1 - basedir
function __iterm_set_bg_color_by_dir {
case $1 in
"example" ) __iterm_set_bg_rgb 0 150 255 ;;
* ) __iterm_set_bg_reset ;;
esac
}
# $1 red (0-255)
# $2 green (0-255)
# $3 blue (0-255)
function __iterm_set_bg_rgb {
__iterm_set_bg_channel red $1
__iterm_set_bg_channel green $2
__iterm_set_bg_channel blue $3
}
function __iterm_set_bg_reset {
echo -ne "\033]6;1;bg;*;default\a"
}
# $1 channel (red, green, blue)
# $2 brightness (0-255)
function __iterm_set_bg_channel {
echo -ne "\033]6;1;bg;$1;brightness;$2\a"
}

4
bash/overrides.sh Normal file
View File

@ -0,0 +1,4 @@
function htop {
__window_title "htop"
/sbin/htop
}

View File

@ -1,28 +0,0 @@
export PATH=/usr/local/bin:$PATH # Homebrew tools
export PATH=$PATH:/usr/local/sbin # Homebrew apps
export PATH=$PATH:$HOME/Dotfiles/bin # My stuff
export PATH=$PATH:$HOME/.bin
# NodeJS
# export PATH=$PATH:/usr/local/share/npm/bin
# Ruby
export PATH=$HOME/.rbenv/versions/2.4.0/bin:$PATH # Gem binaries
export PATH=$HOME/.rbenv/shims:$PATH # Gem binaries
# git achievements
export PATH=$PATH:$PROJECTS/git-achievements
# Go
# export PATH=$PATH:$GOROOT/bin # Go runtime binaries
export PATH=$PATH:$HOME/go/lang/bin # Go package binaries
export PATH=$PATH:$GOPATH/bin # Go package binaries
# Python
# WTF
export PKG_CONFIG_PATH=/usr/local/opt/python3/Frameworks/Python.framework/Versions/3.4/lib/pkgconfig
export PATH=$PATH:/usr/local/Cellar/llvm/8.0.0_1/bin
# Rust
export PATH=$PATH:$HOME/.cargo/bin

13
bash/path.sh Normal file
View File

@ -0,0 +1,13 @@
# Dotfiles
export PATH=$PATH:$HOME/dotfiles/bin # Dotfiles scripts
# Ruby
export PATH=$HOME/.rbenv/versions/$(cat $HOME/.rbenv/version)/bin:$PATH # Gem binaries
export PATH=$HOME/.rbenv/shims:$PATH # Gem binaries
# Go
export PATH=$HOME/go/lang/bin:$PATH # Go package binaries
export PATH=$GOPATH/bin:$PATH # Go package binaries
# Rust
export PATH=$PATH:$HOME/.cargo/bin

View File

@ -1,9 +1,8 @@
GIT="/usr/local/bin/git"
GIT="/sbin/git"
function __bash_prompt {
local baseDir=$(__bash_basedir)
__iterm_set_bg_color_by_dir $baseDir
__iterm_set_title $baseDir
__window_title $baseDir
# Define building blocks
local basedir="$_BOLD$_BLUE\W$_RESET_COLOR$_RESET"

View File

@ -3,25 +3,30 @@
# Step 2: mv ~/Downloads/go ~/go/versions/x.y.z
# GOROOT=$HOME/go/lang
# GOPATH=$HOME/go/path
function gover { ln -sfn $HOME/go/versions/$1 $HOME/go/lang; }
platform=linux-amd64
function gover {
[[ "$1" == "" ]] && go version && return
# TODO: Check it exists
ln -sfn $HOME/go/versions/$1 $HOME/go/lang
}
function _gover { __bash_directory_complete $HOME/go/versions; }
complete -F _gover gover
function godl {
wget https://dl.google.com/go/go$1.darwin-amd64.tar.gz -O /tmp/go$1.darwin-amd64.tar.gz
wget https://dl.google.com/go/go$1.$platform.tar.gz -O /tmp/go$1.$platform.tar.gz
mkdir /tmp/go$1
tar -xzf /tmp/go$1.darwin-amd64.tar.gz -C /tmp/go$1
tar -xzf /tmp/go$1.$platform.tar.gz -C /tmp/go$1
mv /tmp/go$1/go $HOME/go/versions/$1
rmdir /tmp/go$1
}
function __gover_download_list {
curl -s https://golang.org/dl/ \
| grep "https://dl.google.com" \
| grep "/dl/go" \
| cut -d '"' -f6 \
| cut -d/ -f5 \
| cut -d. -f1-3 \
| cut -c3- \
| grep -e '[0-9]\.[0-9]*\.[0-9]' \
| cut -d/ -f3 \
| sed -n -e 's/^go\([0-9]\{1,\}\.[0-9]\{1,\}\(\.[0-9]\{1,\}\)\?\).*/\1/p' \
| sort -Vur
}
function _godl {

68
bash/tools/myc.sh Normal file
View File

@ -0,0 +1,68 @@
#
# MySQL CLI manager
#
# Requirements: mycli, KDE Wallet, jq
export MYCLI_HISTFILE=$HOME/.config/mycli/history
# XXX: Extend this function with custom definitions!
# Override the function (and completions) in dotfiles/secrets/myc.bash
function myc {
case $1 in
e | example )
__myc_connect test example
;;
* )
echo "Usage: myc [serverid]"
;;
esac
}
# NOTE: Completions are based on function definition
complete -W "$(type myc | grep "|" | sed "s/)//" | sed "s/^[ \t]*//" | sed "s/ | / /" | tr '\n' ' ')" myc
function __myc_connect {
envname=$1
dbname=$2
__window_title "MySQL: $dbname @ $envname"
__myc_banner $envname $dbname
creds=$(__myc_creds "$envname-$dbname")
[[ -z "$creds" ]] && echo "Missing credentials!" && return 1
host=$(echo $creds | jq -r .host)
user=$(echo $creds | jq -r .user)
pass=$(echo $creds | jq -r .pass)
defaultdb=$(echo $creds | jq -r .db)
mycli -h $host -u $user -p $pass $defaultdb
}
function __myc_creds {
wallet=kdewallet
folder=MySQL
entry=$1
kwallet-query -f $folder -r $entry $wallet | grep -v "Failed to read entry"
}
function __myc_banner {
envname=$1
db=$2
echo -n "Connecting to ${_BOLD}${db}${_RESET} @ ${_BOLD}"
case $envname in
testing )
echo -n $_YELLOW
;;
production )
echo -n $_RED
;;
localhost )
echo -n $_BLUE
;;
esac
echo "${envname}${_RESET}"
}