Bläddra i källkod

Split local files into `rc` and `env` files

Machine-specific environment settings will now get loaded when other
environment variables do, rather than later. We also move the bash
prompt helper functions to their own file.
Weiyi Lou 10 år sedan
förälder
incheckning
3fb16abc00
5 ändrade filer med 25 tillägg och 18 borttagningar
  1. 3 1
      README.md
  2. 15 0
      shell/bash/prompt.bash
  3. 1 15
      shell/bashrc
  4. 4 0
      shell/env
  5. 2 2
      shell/zshrc

+ 3 - 1
README.md

@@ -48,7 +48,9 @@ Below is a non-exhaustive list of dotfiles usage.
 - Multi-line shell prompt that displays Git repo info and job count.
 - Mostly-Mnemonic Git shortcuts: `gs` = `git status`, `gd` = `git diff`, etc.
 - SSH agent automated - attempts to load identities with `ssh-add` on start.
-- Machine-specific settings can be contained in `.bashlocal` and `.zshlocal`.
+- Machine-specific settings can be contained in `.local` files:
+  - bash: `~/.bashrc.local` and `~/.bashenv.local`
+  - zsh: `~/.zshrc.local` and `~/.zshenv.local`
 
 [z]: https://github.com/rupa/z
 [v]: https://github.com/rupa/v

+ 15 - 0
shell/bash/prompt.bash

@@ -0,0 +1,15 @@
+# Functions used in building the command prompt.
+
+# Display suspended/backgrounded job count, if any.
+function getajob() {
+  local jobcount=$(jobs | wc -l)
+  [[ $jobcount -ne 0 ]] && printf "  ${FG[63]}[jobs]: ${FG[1]}\j" || printf ''
+}
+
+# Display up to 3 segments of the current working directory.
+function shortcwd() {
+  local folder=$(pwd) fld='[^/]*'
+  folder=${folder/$HOME/"~"}
+  folder=$(echo $folder | sed 's|.*/\('$fld'/'$fld'/'$fld'\)|\1|')
+  printf "$folder"
+}

+ 1 - 15
shell/bashrc

@@ -9,8 +9,6 @@ for file in ~/dotfiles/shell/bash/*.bash; do
   source $file
 done
 
-[[ -r ~/.bashlocal ]] && source ~/.bashlocal
-
 # Command Prompt
 #
 #     [host]  directory  gitinfo  jobinfo
@@ -20,18 +18,6 @@ PROMPT_COMMAND='PS1="
 ${FG[6]}[\h]  ${FG[3]}$(shortcwd)$(__gitp "  %s")$(getajob)
 ${FG[5]}\u - $cReset"'
 
-# Display suspended/backgrounded job count, if any.
-function getajob() {
-  local jobcount=$(jobs | wc -l)
-  [[ $jobcount -ne 0 ]] && printf "  ${FG[63]}[jobs]: ${FG[1]}\j" || printf ''
-}
-
-# Display up to 3 segments of the current working directory.
-function shortcwd() {
-  local folder=$(pwd) fld='[^/]*'
-  folder=${folder/$HOME/"~"}
-  folder=$(echo $folder | sed 's|.*/\('$fld'/'$fld'/'$fld'\)|\1|')
-  printf "$folder"
-}
+[[ -r ~/.bashrc.local ]] && source ~/.bashrc.local
 
 [ -f ~/.fzf.bash ] && source ~/.fzf.bash

+ 4 - 0
shell/env

@@ -6,6 +6,10 @@ export PAGER='less'
 export PATH=$HOME/dotfiles/bin:$HOME/bin:$PATH
 export MANPATH=$MANPATH:$HOME/dotfiles/shell/man
 
+# Machine-specific environment settings
+[[ -n ${BASH_VERSION-} && -r ~/.bashenv.local ]] && source ~/.bashenv.local
+[[ -n ${ZSH_VERSION-} && -r ~/.zshenv.local ]] && source ~/.zshenv.local
+
 # Config Files: Which Are Sourced, And When?
 #
 # # BASH

+ 2 - 2
shell/zshrc

@@ -4,8 +4,6 @@ for file in ~/dotfiles/shell/zsh/*.zsh; do
   source $file
 done
 
-[[ -r ~/.zshlocal ]] && source ~/.zshlocal
-
 # Command Prompt
 #
 #     [host]  directory  gitinfo  jobinfo
@@ -17,4 +15,6 @@ $FG[6][%m]  $FG[3]%3~$(__gitp "  %s")%(1j.  $FG[63][jobs]: $FG[1]%j.)
 $FG[5]%n - $cReset'
 RPROMPT='$(vimode) $cReset%T $FG[7]%h$cReset'
 
+[[ -r ~/.zshrc.local ]] && source ~/.zshrc.local
+
 [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh