commit fde5b4ed41c8b0ae4eba6bc8f3fcd857c3bdef99
parent 9a884d646489a431e5b615e00883f60333a42283
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Fri, 2 Oct 2020 14:55:43 +0200
Fix path order & modularise config
The path was being overridden in /etc/zprofile. Renaming it to zshenv
fixed it (since it's loaded before anything else). Info:
https://unix.stackexchange.com/questions/246751/how-to-know-why-and-where-the-path-env-variable-is-set
Also split up into generic and shell-specific files.
Former-commit-id: ea5bf42515e48d3e919fe07accbf9e3a745982b1
Diffstat:
14 files changed, 90 insertions(+), 146 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,6 +1,6 @@
batteryCheck.scpt
.DS_Store
-secret_env_variables
+secret_env
oh-my-zsh/cache
error.log
newsboat/notify-wrapper
diff --git a/dot.map b/dot.map
@@ -55,11 +55,9 @@ emacs:
# Config: shell
shell:
-- zshenv: ~/.zshenv
+- zshenv_bootstrap: ~/.zshenv
+- zshenv: ~/.config/zsh/.zshenv
- zshrc: ~/.config/zsh/.zshrc
-- bash_profile: ~/.bash_profile
-- bashrc: ~/.bashrc
-- profile: ~/.profile
- inputrc: ~/.inputrc
# Config: Vim
diff --git a/install.sh b/install.sh
@@ -50,7 +50,7 @@ case $yn in
;;
esac
-echo "Don't forget to create a ~/.secret_env_variables with:"
+echo "Don't forget to create a $DOTFILES/shell/secret_env with:"
# Don't want these variables to expand
# shellcheck disable=SC2016
echo '- $DISCOGS_API_TOKEN'
diff --git a/shell/bash_profile b/shell/bash_profile
@@ -1 +0,0 @@
-. $HOME/.profile
diff --git a/shell/bashrc b/shell/bashrc
@@ -1,7 +1,5 @@
-. $HOME/.dotfiles/shell/z/z.sh
+#!/usr/bin/env bash
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
-[[ -f $DOTFILES/shell/aliases ]] && source $DOTFILES/shell/aliases
-[[ -f $DOTFILES/shell/functions ]] && source $DOTFILES/shell/functions
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
diff --git a/shell/env b/shell/env
@@ -0,0 +1,30 @@
+#!/bin/sh
+# vim: foldmethod=marker foldlevel=0
+command -v rbenv 1>/dev/null 2>&1 && eval "$(rbenv init -)"
+export DOTFILES="$HOME/.dotfiles"
+EDITOR="$(command -v vim)"; export EDITOR
+export MUSIC_DIR="/Volumes/HDD/Music/iTunes/iTunes Media/Music"
+
+if command -v bat 1>/dev/null 2>&1; then export PAGER="bat"
+else export PAGER="less -R"; fi
+
+export LANG="en_US.UTF-8"
+export LC_ALL="en_US.UTF-8"
+export LC_COLLATE="en_US.UTF-8"
+export LC_CTYPE="UTF-8"
+export LC_MESSAGES="en_US.UTF-8"
+export LC_MONETARY="en_US.UTF-8"
+export LC_NUMERIC="en_US.UTF-8"
+export LC_TIME="en_US.UTF-8"
+
+# Force use of XDG Base Directory {{{1
+alias irssi="irssi --home=$HOME/.config/irssi"
+alias tmux="tmux -f $HOME/.config/tmux/tmux.conf"
+export JUPYTER_CONFIG_DIR="$HOME/.config/jupyter"
+export BUNDLE_USER_HOME="$HOME/.config/bundle"
+export BUNDLE_USER_CACHE="$HOME/.cache/bundle"
+export _Z_DATA="$HOME/.cache/z/z-data"
+export HTTPIE_CONFIG_DIR="$HOME/.config/httpie"
+export CABAL_DIR="$HOME/.config/cabal"
+export GHCUP_INSTALL_BASE_PREFIX="$HOME/.config"
+export ZDOTDIR="$HOME/.config/zsh"
diff --git a/shell/functions b/shell/functions
@@ -1,11 +1,11 @@
-#!/bin/sh bash
+#!/usr/bin/env bash
# vim:foldmethod=indent:foldlevel=0
cd() { builtin cd -P "$@" || return; } # list contents after cding
mkcd() { mkdir -p -- "$1" && cd -P -- "$1" || return; } # make dir and cd at the same time
procinfo() { pgrep -f "$1"; } # get info about a process (by name)
rmempty() { find "${1-.}" -type d -empty -depth -delete; } # remove empty directories
-hr() { for ((i=0; i<$(tput cols); i++)); do echo -n "#"; done; echo; } # insert a <hr> in the terminal
-vimq() { vim -q <(eval $(fc -nl -1)); } # load results of last command (often ag) in vim quickfix. eval necessary to handle escaped quotes.
+hr() { : $((i=0)); while [ $((i<$(tput cols))) -ne 0 ]; do printf "#"; _=$((i=i+1)); done; echo; } # insert a <hr> in the terminal
+vimq() { vim -q <(eval "$(fc -nl -1)"); } # load results of last command (often ag) in vim quickfix. eval necessary to handle escaped quotes.
gpip(){ PIP_REQUIRE_VIRTUALENV="" pip "$@"; } # Access global pip while using virtualenvs
nls() { expr `ls -l | wc -l | xargs echo` - 1; } # Count the number of files in the directory
reload-completions() { rm ~/.zcompdump && compinit; }
diff --git a/shell/paths b/shell/paths
@@ -0,0 +1,14 @@
+#!/bin/sh
+[ -x /usr/libexec/path_helper ] && eval "$(/usr/libexec/path_helper -s)"
+[ -d "$HOME/bin" -o -L "$HOME/bin" ] && [ -n "${PATH##*"$HOME/bin"*}" ] && PATH="$HOME/bin:$PATH"
+[ -d "$HOME/.local/bin" -o -L "$HOME/.local/bin" ] && [ -n "${PATH##*"$HOME/.local/bin"*}" ] && PATH="$HOME/.local/bin:$PATH"
+[ -d "$HOME/.scripts" -o -L "$HOME/.scripts" ] && [ -n "${PATH##*"$HOME/.scripts"*}" ] && PATH="$HOME/.scripts:$PATH"
+[ -d "$HOME/.bin" -o -L "$HOME/.bin" ] && [ -n "${PATH##*"$HOME/.bin"*}" ] && PATH="$HOME/.bin:$PATH"
+[ -d "$HOME/go/bin" -o -L "$HOME/go/bin" ] && [ -n "${PATH##*"$HOME/go/bin"*}" ] && PATH="$HOME/go/bin:$PATH"
+[ -d "/usr/local/opt/util-linux/bin" -o -L "/usr/local/opt/util-linux/bin" ] && [ -n "${PATH##*"/usr/local/opt/util-linux/bin"*}" ] && PATH="/usr/local/opt/util-linux/bin:$PATH"
+[ -d "$HOME/.config/.ghcup/bin" -o -L "$HOME/.config/.ghcup/bin" ] && [ -n "${PATH##*"$HOME/.config/.ghcup/bin"*}" ] && PATH="$HOME/.config/.ghcup/bin:$PATH"
+[ -d "/usr/local/sbin" -o -L "/usr/local/sbin" ] && [ -n "${PATH##*"/usr/local/sbin"*}" ] && PATH="/usr/local/sbin:$PATH"
+[ -d "$HOME/.bin" -o -L "$HOME/.bin" ] && [ -n "${PATH##*"$HOME/.bin"*}" ] && PATH="$HOME/.bin:$PATH"
+[ -d "/usr/local/opt/coreutils/libexec/gnubin" -o -L "/usr/local/opt/coreutils/libexec/gnubin" ] && [ -n "${PATH##*"/usr/local/opt/coreutils/libexec/gnubin"*}" ] && PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
+[ -d "$HOME/.local/gnat/bin" -o -L "$HOME/.local/gnat/bin" ] && [ -n "${PATH##*"$HOME/.local/gnat/bin"*}" ] && PATH="$HOME/.local/gnat/bin:$PATH"
+export PATH
diff --git a/shell/profile b/shell/profile
@@ -1,82 +0,0 @@
-#!/bin/sh
-# ~/.profile: executed by the command interpreter for login shells.
-# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
-# exists.
-# see /usr/share/doc/bash/examples/startup-files for examples.
-# the files are located in the bash-doc package.
-
-# System-wide .profile for sh(1)
-if [ -x /usr/libexec/path_helper ]; then
- eval "$(/usr/libexec/path_helper -s)"
-fi
-
-if [ "${BASH-no}" != "no" ]; then
- [ -r /etc/bashrc ] && . /etc/bashrc
-fi
-
-# if running bash
-if [ -n "$BASH_VERSION" ]; then
- # include .bashrc if it exists
- if [ -f "$HOME/.bashrc" ]; then
- . "$HOME/.bashrc"
- fi
-fi
-
-# set PATH so it includes user's private bin if it exists
-if [ -d "$HOME/bin" ] ; then
- PATH="$HOME/bin:$PATH"
-fi
-
-if [ -d "$HOME/.local/bin" ] ; then
- PATH="$HOME/.local/bin:$PATH"
-fi
-if [ -d "$HOME/.scripts" ] ; then
- PATH="$HOME/.scripts:$PATH"
-fi
-if [ -d "$HOME/.bin" ] ; then
- PATH="$HOME/.bin:$PATH"
-fi
-if [ -d "$HOME/go/bin" ] ; then
- PATH="$HOME/go/bin:$PATH"
-fi
-if [ -d "/usr/local/opt/util-linux/bin" ] ; then
- PATH="/usr/local/opt/util-linux/bin:$PATH"
-fi
-if [ -f "$HOME/.secret_env_variables" ] ; then
- . "$HOME/.secret_env_variables"
-fi
-# Haskell
-if [ -d "$HOME/.config/.ghcup/bin" ]; then
- PATH="$HOME/.config/.ghcup/bin:$PATH"
-fi
-if [ -d "/usr/local/sbin" ]; then
- PATH="/usr/local/sbin:$PATH"
-fi
-if command -v rbenv 1>/dev/null 2>&1; then
- eval "$(rbenv init -)"
-fi
-if [ -d "/usr/local/opt/coreutils/libexec/gnubin" ]; then
- PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
-fi
-if [ -d "$HOME/.local/gnat/bin" ]; then
- PATH="$PATH:$HOME/.local/gnat/bin"
-fi
-
-export DOTFILES="$HOME/.dotfiles"
-EDITOR="$(command -v vim)"; export EDITOR
-export MUSIC_DIR="/Volumes/HDD/Music/iTunes/iTunes Media/Music"
-if command -v bat 1>/dev/null 2>&1; then
- export PAGER="bat"
-else
- export PAGER="less -R"
-fi
-export LANG="en_US.UTF-8"
-export LC_ALL="en_US.UTF-8"
-export LC_COLLATE="en_US.UTF-8"
-export LC_CTYPE="UTF-8"
-export LC_MESSAGES="en_US.UTF-8"
-export LC_MONETARY="en_US.UTF-8"
-export LC_NUMERIC="en_US.UTF-8"
-export LC_TIME="en_US.UTF-8"
-
-. "$DOTFILES/shell/use-config-dir"
diff --git a/shell/rc b/shell/rc
@@ -0,0 +1,25 @@
+#!/bin/sh
+# shellcheck disable=SC2016
+[ -n "$DOTFILES" ] || { printf '$DOTFILES not set, press enter to quit' && read -r && exit 1; }
+
+source_if_exists() { [ -f "$1" ] && . "$1"; }
+
+# Enable virtualenvwrapper if installed
+if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
+ export WORKON_HOME=$HOME/.config/virtualenvs
+ VIRTUALENVWRAPPER_PYTHON=$(which python3); export VIRTUALENVWRAPPER_PYTHON
+ export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
+ mkdir -p "$WORKON_HOME"
+ . /usr/local/bin/virtualenvwrapper_lazy.sh
+fi
+
+(cat ~/.cache/wal/sequences &)
+. ~/.cache/wal/colors-tty.sh
+
+# The 'z' command to jump around dirs
+source_if_exists "$DOTFILES"/shell/z/z.sh
+
+# Enable custom aliases and functions
+source_if_exists "$DOTFILES/shell/aliases"
+source_if_exists "$DOTFILES/shell/functions"
+source_if_exists "$DOTFILES/shell/secret_env"
diff --git a/shell/use-config-dir b/shell/use-config-dir
@@ -1,12 +0,0 @@
-# Make programs use the ~/.config directory
-alias irssi="irssi --home=$HOME/.config/irssi"
-alias tmux="tmux -f $HOME/.config/tmux/tmux.conf"
-
-export JUPYTER_CONFIG_DIR="$HOME/.config/jupyter"
-export BUNDLE_USER_HOME="$HOME/.config/bundle"
-export BUNDLE_USER_CACHE="$HOME/.cache/bundle"
-export _Z_DATA="$HOME/.cache/z/z-data"
-export HTTPIE_CONFIG_DIR="$HOME/.config/httpie"
-export CABAL_DIR="$HOME/.config/cabal"
-export GHCUP_INSTALL_BASE_PREFIX="$HOME/.config"
-export ZDOTDIR="$HOME/.config/zsh"
diff --git a/shell/zshenv b/shell/zshenv
@@ -1,3 +1,6 @@
-. $HOME/.profile
+srcpath="$HOME/.dotfiles/shell"
+. "$srcpath"/env
+. "$srcpath"/paths
+unset srcpath
export ZDOTDIR=$HOME/.config/zsh
export HISTFILE=$ZDOTDIR/.zsh_history
diff --git a/shell/zshenv_bootstrap b/shell/zshenv_bootstrap
@@ -0,0 +1,3 @@
+#!/usr/bin/env zsh
+ZDOTDIR=$HOME/.config/zsh/
+. "$ZDOTDIR"/.zshenv
diff --git a/shell/zshrc b/shell/zshrc
@@ -1,22 +1,18 @@
+# ZSH-specific inits
+. "$DOTFILES"/shell/rc
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block, everything else may go below.
-[ -n "$DOTFILES" ] || { echo '$DOTFILES not set' && exit 1; }
-
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
-source_if_exists() {
- if [[ -f "$1" ]]; then
- source "$1"
- fi
-}
+source_if_exists() { [ -f "$1" ] && . "$1"; }
# Options
if [ -n "$VIMRUNTIME" ]; then set -o vi
-else set -o emacs
-fi
+else set -o emacs; fi
+
setopt alwaystoend # On completion, move cursor to end of word
setopt autocd # If I forget 'cd' before a path
setopt autopushd # Make cd push old directory onto stack
@@ -57,7 +53,7 @@ zle -N bracketed-paste bracketed-paste-magic
# Auto correct commands, with exceptions (from oh-my-zsh)
alias cp='nocorrect cp'
-alias g='nocorrect g'
+alias g='nocorrect git'
alias git='nocorrect git'
alias man='nocorrect man'
alias mkdir='nocorrect mkdir'
@@ -70,31 +66,10 @@ setopt correct_all
# Built-in Tetris (because why not)
alias tetris="autoload -Uz tetriscurses && tetriscurses"
-# Import colorscheme from 'wal' asynchronously
-# & # Run the process in the background.
-# # ( ) # Hide shell job control messages.
-(cat ~/.cache/wal/sequences &)
-
-# # To add support for TTYs this line can be optionally added.
-. ~/.cache/wal/colors-tty.sh
-
-
-# Enable virtualenvwrapper if installed
-if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
- export WORKON_HOME=$HOME/.config/virtualenvs
- export VIRTUALENVWRAPPER_PYTHON=`which python3`
- export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
- mkdir -p $WORKON_HOME
- source /usr/local/bin/virtualenvwrapper_lazy.sh
-fi
-
# Powerlevel10k theme
source_if_exists ~/.p10k.zsh
source_if_exists $DOTFILES/shell/powerlevel10k/powerlevel10k.zsh-theme
-# The 'z' command to jump around dirs
-source_if_exists $DOTFILES/shell/z/z.sh
-
# FZF for fuzzy finding
source_if_exists ~/.fzf.zsh
@@ -102,10 +77,6 @@ source_if_exists ~/.fzf.zsh
source_if_exists $DOTFILES/shell/zsh-plugins/bundler.plugin.zsh
source_if_exists $DOTFILES/shell/zsh-plugins/gitignore.plugin.zsh
-# Enable custom aliases and functions
-source_if_exists "$DOTFILES/shell/aliases"
-source_if_exists "$DOTFILES/shell/functions"
-
insert-arg-of-prev-cmd() {
: ${NUMERIC:-1}
(( NUMERIC++ ))
@@ -140,6 +111,3 @@ bindkey '^Z' _zsh_cli_fg
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
source_if_exists $DOTFILES/shell/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
-
-# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
-[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh