mirror of https://github.com/fredrikekre/.dotfiles
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.9 KiB
129 lines
3.9 KiB
#!/bin/bash |
|
# vim: ft=sh |
|
|
|
# Common commands for .bashrc. Include by adding the following to .bashrc: |
|
# |
|
# # Include cross-system common parts from .dotfiles.git repo |
|
# if [ -f ~/.bashrc.dotfiles ]; then |
|
# . ~/.bashrc.dotfiles |
|
# fi |
|
|
|
# If not running interactively, don't do anything |
|
case $- in |
|
*i*) ;; |
|
*) return;; |
|
esac |
|
|
|
# ssh-agent: start automatically unless SSH_AUTH_SOCK is already set by e.g. ssh-agent forwarding |
|
if command -v ssh-agent &> /dev/null && [ ! -S "${SSH_AUTH_SOCK}" ] && [ -z "${TMUX}" ]; then |
|
eval "$(ssh-agent -t 12h)" > /dev/null |
|
trap 'eval "$(ssh-agent -k)" > /dev/null' EXIT |
|
fi |
|
# ssh-agent: adjust SSH_AUTH_SOCK and SSH_AGENT_PID in tmux session bash prompts |
|
if [ -n "${TMUX}" ]; then |
|
function _tmux_update_environment() { |
|
eval "$(tmux show-environment -s SSH_AUTH_SOCK)" |
|
eval "$(tmux show-environment -s SSH_AGENT_PID)" |
|
} |
|
PROMPT_COMMAND="_tmux_update_environment" |
|
fi |
|
|
|
# gpg-agent: started on demand, but must set GPG_TTY |
|
GPG_TTY=$(tty) |
|
export GPG_TTY |
|
|
|
# Start tmux by default |
|
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then |
|
if grep "default: " <(tmux list-sessions 2> /dev/null) > /dev/null; then |
|
tmux attach -t default |
|
else |
|
tmux new -s default |
|
fi |
|
fi |
|
|
|
# dotfiles alias |
|
alias dotfiles='git --git-dir="$HOME/.dotfiles.git/" --work-tree="$HOME/"' |
|
|
|
# Bash prompt |
|
if [[ "${TERM}" =~ 256 ]]; then |
|
# Colors from vim-airline bubblegum theme: 110 blue, 150 green |
|
PS1="[\[\e[38;5;110m\e[1m\]\u@\h\[\e[0m\]:\[\e[38;5;150m\e[1m\]\w\[\e[0m\]]\$ " |
|
else |
|
PS1="[\[\e[32m\e[1m\]\u@\h\[\e[0m\]:\[\e[34m\e[1m\]\w\[\e[0m\]]\$ " |
|
fi |
|
export PS1 |
|
|
|
|
|
# ls colors |
|
if [[ "${OSTYPE}" == "linux-gnu"* ]] && command -v dircolors &> /dev/null; then |
|
eval "$(dircolors -b)" # Set and export LS_COLORS |
|
alias ls='ls --color=auto' |
|
elif [[ "${OSTYPE}" == "darwin"* ]]; then |
|
if command -v gls &> /dev/null && command -v gdircolors &> /dev/null; then |
|
# Use gnu ls |
|
eval "$(gdircolors -b)" # Set and export LS_COLORS |
|
alias ls='gls --color=auto' |
|
else |
|
export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd |
|
alias ls='ls -G' |
|
fi |
|
fi |
|
|
|
# # Replace standard dircolors with the bubblegum theme from vim-airline, see |
|
# # https://github.com/vim-airline/vim-airline-themes/blob/97cf3e6e638f936187d5f6e9b5eb1bdf0a4df256/autoload/airline/themes/bubblegum.vim |
|
# if [[ "${TERM}" =~ 256 ]]; then |
|
# LS_COLORS=${LS_COLORS//=01;31:/=01;38;5;174:} # Red |
|
# LS_COLORS=${LS_COLORS//=01;32:/=01;38;5;150:} # Green |
|
# LS_COLORS=${LS_COLORS//=01;34:/=01;38;5;110:} # Blue |
|
# LS_COLORS=${LS_COLORS//=01;35:/=01;38;5;182:} # Purple |
|
# LS_COLORS=${LS_COLORS//=00;36:/=00;38;5;80:} # Cyan |
|
# fi |
|
|
|
# Julia environment variables |
|
export JULIA_PKG_DEVDIR=$HOME/dev |
|
export JULIA_PROJECT=@. |
|
export JULIA_PKG_USE_CLI_GIT=true |
|
|
|
# Add private bin directories to PATH |
|
PATH="$HOME/bin:$HOME/.local/bin:$PATH" |
|
|
|
# Enable direnv |
|
if command -v direnv &> /dev/null ; then |
|
eval "$(direnv hook bash)" |
|
# alias tmux='direnv exec / tmux' |
|
fi |
|
|
|
# Set the editor |
|
if command -v nvim &> /dev/null; then |
|
alias vim=nvim |
|
export EDITOR=nvim |
|
else |
|
export EDITOR=vim |
|
fi |
|
|
|
# Wrapper around bw login/unlock that automatically export the session key |
|
if command -v bw &> /dev/null ; then |
|
function bwu () { |
|
if [ -z "${BW_SESSION}" ]; then |
|
export BW_SESSION |
|
case "$(bw status)" in |
|
*"\"unauthenticated\""*) |
|
echo "(bwu) bw login:" |
|
BW_SESSION=$(bw login --raw) |
|
;; |
|
*"\"locked\""*) |
|
echo "(bwu) bw unlock:" |
|
BW_SESSION=$(bw unlock --raw) |
|
;; |
|
esac |
|
fi |
|
} |
|
fi |
|
|
|
# Wrap gh to fetch auth token from bw |
|
if command -v gh &> /dev/null ; then |
|
function gh () { |
|
local TOKEN=${GITHUB_TOKEN:-$(trap '' INT; bw get notes a8aec2cf-0600-4067-b6a6-d2370132f24f)} |
|
GITHUB_TOKEN=${TOKEN} $(which gh) "$@" |
|
}; |
|
fi
|
|
|