diff --git a/.bashrc b/.bashrc index b91d317..8761c43 100644 --- a/.bashrc +++ b/.bashrc @@ -5,8 +5,13 @@ # If not running interactively, don't do anything [[ $- != *i* ]] && return -alias q=exit +# Just in case +export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-"$HOME/.config"}/shell"}" +# Source standard shell configuration +[ -f "$SHELL_CONFIG_DIR/shrc" ] && source "$SHELL_CONFIG_DIR/shrc" + +### Manjaro default bashrc >>> colors() { local fgc bgc vals seq0 @@ -78,10 +83,6 @@ if ${use_color} ; then PS1='\[\033[01;32m\][\u@\h\[\033[01;37m\] \W\[\033[01;32m\]]\$\[\033[00m\] ' fi - alias ls='ls --color=auto' - alias grep='grep --colour=auto' - alias egrep='egrep --colour=auto' - alias fgrep='fgrep --colour=auto' else if [[ ${EUID} == 0 ]] ; then # show root@ when we don't have colors @@ -140,3 +141,6 @@ ex () echo "'$1' is not a valid file" fi } +# <<< + +# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3:ts=3 diff --git a/.config/shell/aliases b/.config/shell/aliases index 98c18fa..ef32ac9 100644 --- a/.config/shell/aliases +++ b/.config/shell/aliases @@ -6,8 +6,8 @@ alias \ vimdiff='nvim -d' alias \ - vv="$EDITOR" \ - e="$EDITOR" \ + vv='$EDITOR' \ + e='$EDITOR' \ sedit='sudoedit' \ # I do this too much by accident smh my head @@ -42,16 +42,22 @@ alias make='make -j$(nproc)' # Colors alias \ ls='ls -hN --color=auto --group-directories-first' \ - grep='grep --color=auto' \ - diff='diff --color=auto' \ - pacman='pacman --color=auto' \ - parue='/usr/bin/paru --color=auto --sudoloop --newsonupgrade --pgpfetch --upgrademenu --bottomup --fm nvim' \ - paru='parue --skipreview' \ + grep='grep --color=auto' \ + egrep='egrep --color=auto' \ + fgrep='fgrep --color=auto' \ + diff='diff --color=auto' \ + pacman='pacman --color=auto' \ -command -v lsd > /dev/null && alias \ - ls=lsd \ - lsd='lsd --group-dirs=first' \ +# super duper paru alias +# shellcheck disable=SC2139 +alias \ + parue="$(which paru) --color=auto --sudoloop --newsonupgrade --pgpfetch --upgrademenu --bottomup --fm nvim" \ + paru='parue --skipreview' +if command -v lsd > /dev/null; then + $IS_TTY && alias ls=lsd + alias lsd='lsd --group-dirs=first' +fi # <<< ## Mini short-hand scripts (ex: glone = git clone) >>> # dotfile management @@ -77,6 +83,7 @@ alias zup='zinit self-update && zinit update --parallel' alias \ nvc='(cd ~/.config/nvim/lua/blake && nvim ../../init.lua)' \ zc='$EDITOR ~/.zshrc' \ + sc='$EDITOR $SHELL_CONFIG_DIR/shrc' \ fstab='sudoedit /etc/fstab' \ hst='$EDITOR $HISTFILE' \ @@ -98,6 +105,7 @@ alias cpv="rsync -ah --info=progress2" alias ls-ports='netstat -tulpn' # list all disks and their mount points +# shellcheck disable=SC2142 alias mnt="mount | awk -F' ' '{ printf \"%s\t%s\n\",\$1,\$3; }' | column -t | grep -E '^/dev/' | sort" # backs up list of packages @@ -113,9 +121,12 @@ alias fds='fd --hidden --exclude /run' SMART_PLUG_IP='192.168.1.250' alias light='tplink_smartplug.py -t $SMART_PLUG_IP -c' -# Common ls aliases +# Common ls aliases alias \ - l=ls \ + l='ls' \ la='ls -ah' \ ll='ls -lh' \ lla='ls -lah' \ +# <<< + +# vim:fdm=marker:fmr=>>>,<<<:fdl=1:et:ft=bash:sw=3:ts=3 diff --git a/.config/shell/env b/.config/shell/env index de2877e..64da3fe 100644 --- a/.config/shell/env +++ b/.config/shell/env @@ -3,7 +3,7 @@ # This file should be compatible with standard sh # shellcheck disable=SC2034 -export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/shell"}" +export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-"$HOME/.config"}/shell"}" if ! [ -d "$SHELL_CONFIG_DIR" ]; then echo "FATAL ERROR: \$SHELL_CONFIG_DIR is not set to a real directory: $SHELL_CONFIG_DIR" fi @@ -63,7 +63,7 @@ export COMPLETION_WAITING_DOTS=true export POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD="${POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD:-true}" export POWERLEVEL9K_INSTANT_PROMPT="${POWERLEVEL9K_INSTANT_PROMPT:-quiet}" # TODO?: maybe add a bit of code to select a random theme if none is detected (make sure to disable instant prompt if this happens) -export P10K_CONFIG_LOCATION="$SHELL_CONFIG_DIR/p10k/current" +export P10K_CONFIG_LOCATION="${P10K_CONFIG_LOCATION:-"$SHELL_CONFIG_DIR/p10k/current"}" # <<< ########################################### diff --git a/.config/shell/profile b/.config/shell/profile new file mode 100644 index 0000000..0e3a7fd --- /dev/null +++ b/.config/shell/profile @@ -0,0 +1,84 @@ +#!/bin/sh +# shellcheck disable=SC2155 + +export PROFILE_LOADED=false + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/.local/bin" ] ; then + PATH="$HOME/.local/bin:$PATH" +fi + +export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-"$HOME/.config"}/shell"}" + +# Locales +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 +export LANGUAGE=en_US.UTF-8 + +# Remove programs from root of home directory +export XDG_CONFIG_HOME="$HOME/.config" +export XDG_DATA_HOME="$HOME/.local/share" +export XDG_CACHE_HOME="$HOME/.cache" +export XDG_RUNTIME_DIR="/run/user/$(id -u)" +export XINITRC="${XDG_CONFIG_HOME:-$HOME/.config}/x11/xinitrc" +#export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority" # This line will break some DMs. +export GTK2_RC_FILES="${XDG_CONFIG_HOME:-$HOME/.config}/gtk-2.0/gtkrc-2.0" +export LESSHISTFILE="-" +export ALSA_CONFIG_PATH="$XDG_CONFIG_HOME/alsa/asoundrc" +# export GNUPGHOME="${XDG_DATA_HOME:-$HOME/.local/share}/gnupg" +export WINEPREFIX="${XDG_DATA_HOME:-$HOME/.local/share}/wineprefixes/default" +export KODI_DATA="${XDG_DATA_HOME:-$HOME/.local/share}/kodi" +# export TMUX_TMPDIR="$XDG_RUNTIME_DIR" +# export ANDROID_SDK_HOME="${XDG_CONFIG_HOME:-$HOME/.config}/android" +# export CARGO_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/cargo" +export GOPATH="${XDG_DATA_HOME:-$HOME/.local/share}/go" + +[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env" + +# Other programs +export FZF_DEFAULT_OPTS="--layout=reverse --height 33%" +export LESS=-R +export LESS_TERMCAP_mb="$(printf '%b' '[1;31m')" +export LESS_TERMCAP_md="$(printf '%b' '[1;36m')" +export LESS_TERMCAP_me="$(printf '%b' '[0m')" +export LESS_TERMCAP_so="$(printf '%b' '[01;44;33m')" +export LESS_TERMCAP_se="$(printf '%b' '[0m')" +export LESS_TERMCAP_us="$(printf '%b' '[1;32m')" +export LESS_TERMCAP_ue="$(printf '%b' '[0m')" +export MOZ_USE_XINPUT2="1" # Mozilla smooth scrolling/touchpads. +export VDPAU_DRIVER=va_gl # Fix steam remote play black screen +# shellcheck disable=SC2046 +export $(dbus-launch) + +# If running in a TTY… +if [ "$(tty | sed 's-[0-9]$--g')" = /dev/tty ]; then + export IS_TTY=true + + # 1- Swap caps and escape + TMP_KEYMAP=/tmp/keymap_tmp.kmap + cat <<-EOF >> "$TMP_KEYMAP" + keycode 1 = Caps_Lock + keycode 58 = Escape + EOF + sudo -n loadkeys "$TMP_KEYMAP" 2>/dev/null + rm "$TMP_KEYMAP" + + # 2- Change the prompt theme to one that doesn't use nerdfonts + export P10K_CONFIG_LOCATION="$HOME/.config/shell/p10k/simple.p10k.zsh" + +else + export IS_TTY=false + + # gnome likes to reset the keymap settings I make and I hate it + # if… gnome is the desktop, the profile is unloaded, we are not in tmux, and gsettings is a valid command + if [ "$DESKTOP_SESSION" = "gnome" ] && [ -z "${PROFILE_LOADED+foo}" ] && [ -z "${TMUX+foo}" ] && command -v gsettings > /dev/null; then + ( + sleep 1 && + gsettings set org.gnome.desktop.input-sources xkb-options "['caps:escape', 'compose:sclk']" + ) & + fi +fi + +export PROFILE_LOADED=true + +# vim:ft=sh:sw=3:ts=3:nospell diff --git a/.config/shell/shrc b/.config/shell/shrc new file mode 100644 index 0000000..ca504b8 --- /dev/null +++ b/.config/shell/shrc @@ -0,0 +1,87 @@ +# Blakely's basic shell setup file + +# This file is compatible with basic `sh`, and can +# be sourced in all `sh`-compatible shells to get +# the basic parts of the local `sh` configuration. + +### Pre-setup >>> +# shellcheck disable=SC1090,SC2296,SC1091,SC2154,SC2015 + +# Helper function to source files. +# Usage: +# careful_source "file" \ +# [optional: "Error message"] \ +# [optional: $LINENO] (use this if you have an error message) \ +# [optional: test to run] (-f, -x, -e) \ +# [optional: operation (source, exec, command or nothing)] \ +careful_source() { + if test "${4:--f}" "$1"; then + ${5:-source} "$1" + else + if test -n "${2+foo}"; then + echo -e "$2" >&2 + echo "Line number: $3" >&2 + fi + fi +} + +# for sending error messages from functions and whatnot +error() { + ERROR_CODE="$?" + >&2 echo "(zshrc) An error occurred on line number ${1}" + return $ERROR_CODE +} + +# change cursor to a beam by default +echo -ne '\e[5 q' + +### <<< +### Generic shell configuration >>> +### Environment variables >>> + +# This has to go here because otherwise we don't know where the config files are :| +export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/shell"}" + +# source the environment variable file +${SKIP_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/env" \ + "Error: could not locate env file. Things could be messed up. Check that \$SHELL_CONFIG_DIR/env exists." $LINENO + +${SKIP_LOCAL_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/local/env" \ + +# <<< +### Aliases >>> +# Source the alias file +${SKIP_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/aliases" \ + "Error: could not locate alias file. You may not have any aliases. Check that \$SHELL_CONFIG_DIR points to the right place." $LINENO + +${SKIP_LOCAL_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/local/aliases" + +# <<< +### Functions >>> +# Organization: functions that are really short should be put here, otherwise +# they should be put in a file located in $SHELL_CONFIG_DIR/functions. If they +# can be converted into a script, they should be. +# +# To make a "function in a file" that fits with my personal spec, simply make a +# file, name it what the function is called, and put the function inside of it +# just like you would if you were writing it here. + +# load all functions that are stored in files +fnupdate() { + for FN in "$SHELL_CONFIG_DIR"/functions/*;do + source "$FN" + done +} +${SKIP_FUNCTIONS:-false} || fnupdate + +# <<< +### Options >>> +set -o vi +# <<< +# <<< +### Apply breaking changes with the update script >>> +${SKIP_UPDATES:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \ + "Error: failed to run update script" $LINENO -x "command" +### <<< + +# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3:ts=3 diff --git a/.zshrc b/.zshrc index 62cc1c0..2655ce2 100644 --- a/.zshrc +++ b/.zshrc @@ -1,81 +1,10 @@ # Blake's ZSH configuration file -### Pre-setup >>> -# shellcheck disable=SC1090,SC2296,SC1091,SC2154,SC2015 +# Just in case +export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-"$HOME/.config"}/shell"}" -# Helper function to source files. -# Usage: -# careful_source "file" \ -# [optional: "Error message"] \ -# [optional: $LINENO] (use this if you have an error message) \ -# [optional: test to run] (-f, -x, -e) \ -# [optional: operation (source, exec, command or nothing)] \ -careful_source() { - if test "${4:--f}" "$1"; then - ${5:-source} "$1" - else - if test -n "${2+foo}"; then - echo -e "$2" >&2 - echo "Line number: $3" >&2 - fi - fi -} - -# for sending error messages from functions and whatnot -error() { - ERROR_CODE="$?" - >&2 echo "(zshrc) An error occurred on line number ${1}" - return $ERROR_CODE -} - -# change cursor to a beam by default -echo -ne '\e[5 q' - -### <<< -### Generic shell configuration >>> -### Environment variables >>> - -# This has to go here because otherwise we don't know where the config files are :| -export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/shell"}" - -# source the environment variable file -${SKIP_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/env" \ - "Error: could not locate env file. Things could be messed up. Check that \$SHELL_CONFIG_DIR/env exists." $LINENO - -${SKIP_LOCAL_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/local/env" \ - -# <<< -### Aliases >>> -# Source the alias file -${SKIP_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/aliases" \ - "Error: could not locate alias file. You may not have any aliases. Check that \$SHELL_CONFIG_DIR points to the right place." $LINENO - -${SKIP_LOCAL_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/local/aliases" - -# <<< -### Functions >>> -# Organization: functions that are really short should be put here, otherwise -# they should be put in a file located in $SHELL_CONFIG_DIR/functions. If they -# can be converted into a script, they should be. -# -# To make a "function in a file" that fits with my personal spec, simply make a -# file, name it what the function is called, and put the function inside of it -# just like you would if you were writing it here. - -# load all functions that are stored in files -fnupdate() { - for FN in "$SHELL_CONFIG_DIR"/functions/*;do - source "$FN" - done -} -${SKIP_FUNCTIONS:-false} || fnupdate - -# <<< -# <<< -### Apply breaking changes with the update script >>> -${SKIP_UPDATES:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \ - "Error: failed to run update script" $LINENO -x "command" -### <<< +# Source standard shell configuration +[ -f "$SHELL_CONFIG_DIR/shrc" ] && source "$SHELL_CONFIG_DIR/shrc" ### Plugins >>> ${SKIP_PLUGINS:-false} || {