From d7257d876b439878f8458ec57f2db2edd0d1b689 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Sun, 20 Jan 2019 16:16:17 +0000 Subject: [PATCH] Move uncommon bash config items out of .bashrc and deploy them via Ansible --- .../roles/mac_desktop/tasks/homebrew.yaml | 56 +++++++- .ansible/roles/mac_desktop/tasks/prefs.yaml | 134 +++++++++++------- .bashrc | 81 +---------- .bashrc.d/go | 5 + .bashrc.d/history | 16 +++ .bashrc.d/ssh-agent | 16 +++ .bashrc_local.sample | 4 - 7 files changed, 170 insertions(+), 142 deletions(-) create mode 100644 .bashrc.d/go create mode 100644 .bashrc.d/history create mode 100644 .bashrc.d/ssh-agent delete mode 100644 .bashrc_local.sample diff --git a/.ansible/roles/mac_desktop/tasks/homebrew.yaml b/.ansible/roles/mac_desktop/tasks/homebrew.yaml index 75ee964..b44fa3f 100644 --- a/.ansible/roles/mac_desktop/tasks/homebrew.yaml +++ b/.ansible/roles/mac_desktop/tasks/homebrew.yaml @@ -1,51 +1,93 @@ # Install Homebrew -- name: Check for Homebrew +- name: 'Brew: Check if already installed' tags: - install + - brew stat: path: /usr/local/bin/brew register: st -- name: Install Homebrew +- name: 'Brew: Install' tags: - install + - brew command: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" when: st.stat.executable != True -- name: Disable Homebrew analytics +- name: 'Brew: Disable analytics' + tags: + - config + - brew command: brew analytics off # Taps -- name: Install Homebrew Taps +- name: 'Brew: Install Taps' tags: - install + - brew + - packages homebrew_tap: name: "{{ item }}" state: present loop: "{{ homebrew_tap_items }}" # Update and upgrades -- name: Homebrew update and upgrades +- name: 'Brew: Update and upgrades' tags: - install + - brew + - upgrade + - update homebrew: update_homebrew: True upgrade_all: True # Brews -- name: Install Homebrew Brews +- name: 'Brew: Install packages' tags: - install + - brew + - packages homebrew: name: "{{ item }}" state: present loop: "{{ homebrew_brew_items }}" # Casks -- name: Install Homebrew Casks +- name: 'Brew: Install Casks' tags: - install + - brew + - cask + - packages homebrew_cask: name: "{{ item }}" state: present loop: "{{ homebrew_cask_items }}" + +# Config +- name: 'Brew: Bash completion' + tags: + - config + - brew + - shell + copy: + content: | + if [ -f $(brew --prefix 2>/dev/null)/etc/bash_completion ]; then + . $(brew --prefix 2>/dev/null)/etc/bash_completion + fi + dest: '~/.bashrc.d/homebew_bash_completion' + mode: '0400' + +- name: 'Brew: API token' + tags: + - config + - homebrew + - shell + copy: + content: | + if [ -x "$(which brew 2>/dev/null)" ]; then + export HOMEBREW_GITHUB_API_TOKEN=$(getkey HOMEBREW_GITHUB_API_TOKEN) + fi + dest: '~/.bashrc.d/homebrew_token' + mode: '0400' diff --git a/.ansible/roles/mac_desktop/tasks/prefs.yaml b/.ansible/roles/mac_desktop/tasks/prefs.yaml index 25b44ba..cf5ab75 100644 --- a/.ansible/roles/mac_desktop/tasks/prefs.yaml +++ b/.ansible/roles/mac_desktop/tasks/prefs.yaml @@ -3,26 +3,62 @@ - config - iterm2 template: - src: "{{ item }}" + src: "iterm2/{{ item }}" dest: '~/.iterm2' mode: '0600' - loop: "{{ query('fileglob', 'iterm2/*') }}" + loop: ['com.googlecode.iterm2.plist', 'hybrid.itermcolors'] + +- name: 'Iterm2: Shell integration' + tags: + - config + - iterm2 + copy: + src: 'iterm2/shell_integration.bash' + dest: '~/.bashrc.d' + mode: '0400' + +- name: 'Shell: ps alias' + tags: + - config + - shell + copy: + content: | + [[ -x /bin/ps && -x $(which pstree 2>/dev/null) && $(uname -s) = 'Darwin' ]] && function ps() { if [[ ${1} =~ 'f' ]]; then pstree; else /bin/ps ${@}; fi } + dest: '~/.bashrc.d/alias.ps' + mode: '0400' + +- name: 'Shell: GNU overrides' + tags: + - config + - shell + copy: + content: | + [[ -x $(which gdu 2>/dev/null) ]] && function du() { gdu ${@}; } && export -f du + [[ -x $(which gsort 2>/dev/null) ]] && function sort() { gsort ${@}; } && export -f sort + dest: '~/.bashrc.d/alias.gnu' + mode: '0400' - name: 'Firefox: Set base path' tags: - config + - firefox + - browser set_fact: firefox_path: '~/Library/Application Support/Firefox' - name: 'Firefox: Find profile path' tags: - config + - firefox + - browser set_fact: profile_path: "{{ lookup('ini', 'Path section=Profile0 file=' + firefox_path + '/profiles.ini') }}" - name: 'Firefox: Add local config' tags: - config + - firefox + - browser copy: content: | user_pref("geo.enabled", false); @@ -31,61 +67,53 @@ dest: "{{ firefox_path }}/{{ profile_path }}/user.js" mode: '0600' -- name: 'OS X: Dock orientation' +- name: 'OS X: Preferences' tags: - config - osx_defaults: - domain: com.apple.dock - type: string - key: orientation - value: right + - os + - osx + block: + - name: 'OS X: Dock orientation' + osx_defaults: + domain: com.apple.dock + type: string + key: orientation + value: right -- name: 'OS X: Dock size' - tags: - - config - osx_defaults: - domain: com.apple.dock - type: float - key: tilesize - value: '35' + - name: 'OS X: Dock size' + osx_defaults: + domain: com.apple.dock + type: float + key: tilesize + value: '35' -- name: 'OS X: Smart quotes off' - tags: - - config - osx_defaults: - domain: NSGlobalDomain - type: int - key: NSAutomaticQuoteSubstitutionEnabled - value: '0' + - name: 'OS X: Smart quotes off' + osx_defaults: + domain: NSGlobalDomain + type: int + key: NSAutomaticQuoteSubstitutionEnabled + value: '0' -- name: 'OS X: Smart dashes off' - tags: - - config - osx_defaults: - domain: NSGlobalDomain - type: int - key: NSAutomaticDashSubstitutionEnabled - value: '0' + - name: 'OS X: Smart dashes off' + osx_defaults: + domain: NSGlobalDomain + type: int + key: NSAutomaticDashSubstitutionEnabled + value: '0' -- name: 'OS X: Spell correction off' - tags: - - config - osx_defaults: - domain: NSGlobalDomain - type: int - key: NSAutomaticSpellingCorrectionEnabled - value: '0' + - name: 'OS X: Spell correction off' + osx_defaults: + domain: NSGlobalDomain + type: int + key: NSAutomaticSpellingCorrectionEnabled + value: '0' -- name: 'OS X: Web spell correction off' - tags: - - config - osx_defaults: - domain: NSGlobalDomain - type: int - key: WebAutomaticSpellingCorrectionEnabled - value: '0' - -- name: 'OS X: Clear preferences cache' - tags: - - config - command: 'pkill -u ${USER} cfprefsd' + - name: 'OS X: Web spell correction off' + osx_defaults: + domain: NSGlobalDomain + type: int + key: WebAutomaticSpellingCorrectionEnabled + value: '0' + always: + - name: 'OS X: Clear preferences cache' + command: 'pkill -u ${USER} cfprefsd' diff --git a/.bashrc b/.bashrc index 372df71..b7b3446 100755 --- a/.bashrc +++ b/.bashrc @@ -64,26 +64,6 @@ pathadd /usr/local/bin pathadd ~/bin #-------------------------------------------------------------------------------- -#-------------------------------------------------------------------------------- -# Set some variables -#-------------------------------------------------------------------------------- -# Add the Homebrew API token, if appropriate -if [ -x "$(which brew 2>/dev/null)" ]; then - export HOMEBREW_GITHUB_API_TOKEN=$(getkey HOMEBREW_GITHUB_API_TOKEN) -fi -#-------------------------------------------------------------------------------- - -#-------------------------------------------------------------------------------- -# Add bash completion scripts (deferred until the end and backgrounded) -#-------------------------------------------------------------------------------- -function _deferred { - # Bash completion with Homebrew - if [ -f $(brew --prefix 2>/dev/null)/etc/bash_completion ]; then - . $(brew --prefix 2>/dev/null)/etc/bash_completion - fi -} -#-------------------------------------------------------------------------------- - #-------------------------------------------------------------------------------- # A useful prompt #-------------------------------------------------------------------------------- @@ -97,23 +77,6 @@ export PROMPT_COMMAND="${PROMPT_COMMAND:+"${PROMPT_COMMAND%%';__PROMPT_COMMAND'} export PROMPT_COMMAND="${PROMPT_COMMAND//;;/;}" #-------------------------------------------------------------------------------- -#-------------------------------------------------------------------------------- -# Record history for longer and more dynamically -#-------------------------------------------------------------------------------- -# Unlimited history buffer -export HISTSIZE= -export HISTFILESIZE= - -# Avoid duplicates in the history... -export HISTCONTROL=ignoreboth - -# Record the timestamp in the bash history -export HISTTIMEFORMAT="%Y-%m-%d %T " - -# Append history entries... -shopt -s histappend -#-------------------------------------------------------------------------------- - #-------------------------------------------------------------------------------- # Command alias functions #-------------------------------------------------------------------------------- @@ -122,51 +85,13 @@ function space() { du -ahx --max-depth=1 | sort -h; } && export -f space if ! alias ll >/dev/null 2>&1; then function ll() { ls -l ${@}; } && export -f ll; fi [[ ! -x $(which psgrep 2>/dev/null) ]] && function psgrep() { ps -ef | grep ${@} | grep -v ${$}; } && export -f psgrep [[ -x $(which glances 2>/dev/null) ]] && function top() { glances; } && export -f top -[[ -x $(which gdu 2>/dev/null) ]] && function du() { gdu ${@}; } && export -f du -[[ -x $(which gsort 2>/dev/null) ]] && function sort() { gsort ${@}; } && export -f sort -[[ -x /bin/ps && -x $(which pstree 2>/dev/null) && $(uname -s) = 'Darwin' ]] && function ps() { if [[ ${1} =~ 'f' ]]; then pstree; else /bin/ps ${@}; fi } [[ -x $(which tree 2>/dev/null) ]] && alias tree="tree -AQh --du" + export GIT_SSH_COMMAND="$(which ssh) -o RemoteCommand=none" #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- -# Set up GOPATH for Go development +# Include deployed bash config #-------------------------------------------------------------------------------- -export GOPATH=${HOME} -#-------------------------------------------------------------------------------- - -#-------------------------------------------------------------------------------- -# Run an SSH agent, if possible -#-------------------------------------------------------------------------------- -# Check if we already have an agent running and sourced -if [ -z "${SSH_AUTH_SOCK}" ]; then - SSH_AUTH_SOCK_FILE=~/.ssh/auth_sock - if [ -S ${SSH_AUTH_SOCK_FILE} ]; then - export SSH_AUTH_SOCK=${SSH_AUTH_SOCK_FILE} - export SSH_AGENT_PID=$(cat ~/.ssh/agent.pid) - else - eval `ssh-agent -a ${SSH_AUTH_SOCK_FILE} -s` - echo ${SSH_AGENT_PID} > ~/.ssh/agent.pid - ssh-add - fi -fi -#-------------------------------------------------------------------------------- - -#-------------------------------------------------------------------------------- -# iTerm2 shell integration -#-------------------------------------------------------------------------------- -[ -f ~/.iterm2/shell_integration.bash ] && source ~/.iterm2/shell_integration.bash -#-------------------------------------------------------------------------------- - -#-------------------------------------------------------------------------------- -# Run local .bashrc for any local-only commands -#-------------------------------------------------------------------------------- -[ -f ~/.bashrc_local ] && source ~/.bashrc_local -#-------------------------------------------------------------------------------- - -#-------------------------------------------------------------------------------- -# Kick off the _deferred() function and background it (speeding up Bash loading) -#-------------------------------------------------------------------------------- -trap '_deferred 2>/dev/null; trap USR1' USR1 -{ sleep 0.1 ; builtin kill -USR1 $$ ; } & disown +source ~/.bashrc.d/* 2>/dev/null #-------------------------------------------------------------------------------- diff --git a/.bashrc.d/go b/.bashrc.d/go new file mode 100644 index 0000000..b0ce03c --- /dev/null +++ b/.bashrc.d/go @@ -0,0 +1,5 @@ +#-------------------------------------------------------------------------------- +# Set up GOPATH for Go development +#-------------------------------------------------------------------------------- +export GOPATH=${HOME} +#-------------------------------------------------------------------------------- diff --git a/.bashrc.d/history b/.bashrc.d/history new file mode 100644 index 0000000..0231fae --- /dev/null +++ b/.bashrc.d/history @@ -0,0 +1,16 @@ +#-------------------------------------------------------------------------------- +# Record history for longer and more dynamically +#-------------------------------------------------------------------------------- +# Unlimited history buffer +export HISTSIZE= +export HISTFILESIZE= + +# Avoid duplicates in the history... +export HISTCONTROL=ignoreboth + +# Record the timestamp in the bash history +export HISTTIMEFORMAT="%Y-%m-%d %T " + +# Append history entries... +shopt -s histappend +#-------------------------------------------------------------------------------- diff --git a/.bashrc.d/ssh-agent b/.bashrc.d/ssh-agent new file mode 100644 index 0000000..c5a8fc5 --- /dev/null +++ b/.bashrc.d/ssh-agent @@ -0,0 +1,16 @@ +#-------------------------------------------------------------------------------- +# Run an SSH agent, if possible +#-------------------------------------------------------------------------------- +# Check if we already have an agent running and sourced +if [ -z "${SSH_AUTH_SOCK}" ]; then + SSH_AUTH_SOCK_FILE=~/.ssh/auth_sock + if [ -S ${SSH_AUTH_SOCK_FILE} ]; then + export SSH_AUTH_SOCK=${SSH_AUTH_SOCK_FILE} + export SSH_AGENT_PID=$(cat ~/.ssh/agent.pid) + else + eval `ssh-agent -a ${SSH_AUTH_SOCK_FILE} -s` + echo ${SSH_AGENT_PID} > ~/.ssh/agent.pid + ssh-add + fi +fi +#-------------------------------------------------------------------------------- diff --git a/.bashrc_local.sample b/.bashrc_local.sample deleted file mode 100644 index 5d20777..0000000 --- a/.bashrc_local.sample +++ /dev/null @@ -1,4 +0,0 @@ -# Launch/restore screen -if [ -x $(which screen 2>/dev/null) ]; then - if [ -z "$STY" ]; then exec screen -xRR; fi -fi