commit baf10f9ddce8ccccc2dcbc2034aa4fe2824355d4
parent 1e02c308f124f6caae4d656b2da002b7ea446c70
Author: Robert Russell <robert@rr3.xyz>
Date: Sun, 26 Jul 2026 21:02:38 -0700
Turn shell config into graft package
Diffstat:
16 files changed, 147 insertions(+), 37 deletions(-)
diff --git a/.bashrc b/.bashrc
@@ -1,25 +0,0 @@
-# If not running interactively, don't do anything
-[[ $- != *i* ]] && return
-
-alias ls='ls --color=auto'
-alias e=vis
-alias o=xdg-open
-alias ..='cd ..'
-
-PROMPT_COMMAND='PS1EXIT=$?;' # Store previous exit code in PS1EXIT
-PROMPT_COMMAND+='printf "\e[6n";' # Query cursor position (format: \e[<row>;<col>R)
-PROMPT_COMMAND+='read -sd";";' # Ignore upto ";"
-PROMPT_COMMAND+='read -sdR PS1COL;' # Store column number in PS1COL
-PROMPT_COMMAND+='PS1="";' # Initialize PS1
-PROMPT_COMMAND+='[ ${PS1COL:-1} -ne 1 ] && PS1+="\[\e[31;1m\]◆\[\e[m\]\n";' # If current row is nonempty, add newline to PS1
-PROMPT_COMMAND+='PS1+="\[\e[36m\]\w\[\e[m\]";' # Add working directory to PS1
-PROMPT_COMMAND+='git rev-parse --git-dir >/dev/null 2>&1' # Check if inside git repo;
-PROMPT_COMMAND+=' && PS1+=" \[\e[35m\] $(git branch --show-current)\[\e[m\]";' # if so, add branch name to PS1
-PROMPT_COMMAND+='PS1+=" \[\e[31m\]$PS1EXIT\[\e[m\]";' # Add previous exit code to PS1
-PROMPT_COMMAND+='PS1+="\n\[\e[32m\]▶\[\e[m\] ";' # Add actual prompt to PS1
-
-PS2='\[\e[32m\]▷\[\e[m\] '
-
-source ~/app/z/z.sh
-
-[ -f "$HOME/.ghcup/env" ] && . "$HOME/.ghcup/env" # ghcup-env
diff --git a/.profile b/.profile
@@ -1,12 +0,0 @@
-export EDITOR=vis
-export BROWSER=firefox
-export PAGER=less
-export PDFVIEWER=firefox
-export PATH="$PATH:$HOME/.local/bin:$HOME/.cabal/bin:/opt/ats2/bin:/opt/idris2/bin:$HOME/.elan/bin:$HOME/go/bin"
-export PATSHOME="/opt/ats2/lib/ats2-postiats-0.4.2"
-export SSH_AUTH_SOCK="$HOME/.ssh/agent/ssh-agent.sock"
-
-# opam configuration
-test -r $HOME/.opam/opam-init/init.sh && . $HOME/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true
-
-[ -f "$HOME/.ghcup/env" ] && . "$HOME/.ghcup/env" # ghcup-env
diff --git a/shell/.bash_profile b/shell/.bash_profile
@@ -0,0 +1,10 @@
+true # In case anything tries prepending below comments.
+# ↑↑↑ MACHINE GENERATED ↑↑↑
+# ------------------------------------------------------------------------------
+
+[ -f "$HOME"/.profile ] && . "$HOME"/.profile
+[ -f "$HOME"/.bashrc ] && . "$HOME"/.bashrc
+
+# ------------------------------------------------------------------------------
+# ↓↓↓ MACHINE GENERATED ↓↓↓
+true # In case anything tries appending above comments.
diff --git a/shell/.bashrc b/shell/.bashrc
@@ -0,0 +1,12 @@
+true # In case anything tries prepending below comments.
+# ↑↑↑ MACHINE GENERATED ↑↑↑
+# ------------------------------------------------------------------------------
+
+[ -f "$HOME"/.shinit ] && . "$HOME"/.shinit
+is_interactive || return
+[ -f "$HOME"/.shrc ] && . "$HOME"/.shrc
+sourcedir "$HOME"/.config/bashrc.d
+
+# ------------------------------------------------------------------------------
+# ↓↓↓ MACHINE GENERATED ↓↓↓
+true # In case anything tries appending above comments.
diff --git a/shell/.config/bashrc.d/50-prompt.sh b/shell/.config/bashrc.d/50-prompt.sh
@@ -0,0 +1,20 @@
+prompt_command() {
+ local prev_exit=$?
+
+ # Query cursor position (format: \e[<row>;<col>R)
+ printf "\e[6n"
+ read -rsd";"
+ read -rsdR PS1COL
+
+ PS1=""
+ [ "${PS1COL:-1}" -ne 1 ] && PS1+="\[\e[31;1m\]◆\[\e[m\]\n" # If current row is nonempty, add newline to PS1
+ PS1+="\[\e[36m\]\w\[\e[m\]" # Add working directory to PS1
+ if have git && git rev-parse --git-dir >/dev/null 2>&1; then # If in git repo...
+ PS1+=" \[\e[35m\] $(git branch --show-current)\[\e[m\]" # ...add branch name to PS1
+ fi
+ PS1+=" \[\e[31m\]$prev_exit\[\e[m\]" # Add previous exit code to PS1
+ PS1+="\n\[\e[32m\]▶\[\e[m\] " # Add actual prompt to PS1
+}
+
+export PROMPT_COMMAND=prompt_command
+export PS2='\[\e[32m\]▷\[\e[m\] '
diff --git a/shell/.config/profile.d/10-path.sh b/shell/.config/profile.d/10-path.sh
@@ -0,0 +1,6 @@
+append_path "$HOME"/.local/bin
+append_path "$HOME"/.cabal/bin
+append_path "$HOME"/.elan/bin
+append_path "$HOME"/go/bin
+
+export PATH
diff --git a/shell/.config/profile.d/70-programs.sh b/shell/.config/profile.d/70-programs.sh
@@ -0,0 +1,4 @@
+export EDITOR=vis
+export BROWSER=firefox
+export PAGER=less
+export PDFVIEWER=firefox
diff --git a/shell/.config/profile.d/90-env.sh b/shell/.config/profile.d/90-env.sh
@@ -0,0 +1 @@
+export ENV="$HOME"/.shrc
diff --git a/shell/.config/shinit.d/10-util.sh b/shell/.config/shinit.d/10-util.sh
@@ -0,0 +1,38 @@
+have() {
+ if [ $# -ne 1 ]; then
+ echo "Usage: have COMMAND" 1>&2
+ return 1
+ fi
+
+ command -v "$1" >/dev/null 2>&1
+}
+
+append_path() {
+ for p in "$@"; do
+ case ":$PATH:" in
+ *:"$p":*) ;;
+ *) PATH="${PATH:+$PATH:}$p"
+ esac
+ done
+}
+
+prepend_path() {
+ for p in "$@"; do
+ case ":$PATH:" in
+ *:"$p":*) ;;
+ *) PATH="$p${PATH:+:$PATH}"
+ esac
+ done
+}
+
+is_interactive() {
+ if [ $# -ne 0 ]; then
+ echo "Usage: is_interactive" 1>&2
+ return 1
+ fi
+
+ case $- in
+ *i*) true ;;
+ *) false ;;
+ esac
+}
diff --git a/shell/.config/shrc.d/50-prompt.sh b/shell/.config/shrc.d/50-prompt.sh
@@ -0,0 +1,6 @@
+if [ "$(id -u)" -eq 0 ]; then
+ PS1='${PWD} $ '
+else
+ PS1='${PWD} # '
+fi
+export PS1
diff --git a/shell/.config/shrc.d/60-aliases.sh b/shell/.config/shrc.d/60-aliases.sh
@@ -0,0 +1,3 @@
+alias ls='ls --color=auto'
+alias e='$EDITOR'
+alias o=xdg-open
diff --git a/shell/.graft.sh b/shell/.graft.sh
@@ -0,0 +1,9 @@
+copy .bash_profile
+copy .bashrc
+copy .profile
+copy .shinit
+copy .shrc
+
+for f in .config/*/*.sh; do
+ link "$f"
+done
diff --git a/shell/.profile b/shell/.profile
@@ -0,0 +1,10 @@
+true # In case anything tries prepending below comments.
+# ↑↑↑ MACHINE GENERATED ↑↑↑
+# ------------------------------------------------------------------------------
+
+[ -f "$HOME"/.shinit ] && . "$HOME"/.shinit
+sourcedir "$HOME"/.config/profile.d
+
+# ------------------------------------------------------------------------------
+# ↓↓↓ MACHINE GENERATED ↓↓↓
+true # In case anything tries appending above comments.
diff --git a/shell/.shinit b/shell/.shinit
@@ -0,0 +1,20 @@
+[ -n "${SHINIT_LOADED:-}" ] && return
+SHINIT_LOADED=1
+
+sourcedir() {
+ if [ $# -ne 1 ]; then
+ echo "Usage: sourcedir DIR" 1>&2
+ return 1
+ fi
+
+ if [ -d "$1" ]; then
+ for f in "$1"/*.sh; do
+ [ -f "$f" ] && . "$f"
+ done
+ unset f
+ fi
+
+ return 0
+}
+
+sourcedir "$HOME"/.config/shinit.d
diff --git a/shell/.shrc b/shell/.shrc
@@ -0,0 +1,3 @@
+[ -f "$HOME"/.shinit ] && . "$HOME"/.shinit
+is_interactive || return
+sourcedir "$HOME"/.config/shrc.d
diff --git a/shell/README b/shell/README
@@ -0,0 +1,5 @@
+Shell config source order:
+ 1. shinit, always
+ 2. profile, if login
+ 3. shrc, if interactive
+ 4. bashrc, if interactive