Add basic XDG compliant sh architecture

This commit is contained in:
Marty Oehme 2020-02-01 14:37:16 +01:00
parent a0a02be852
commit 3aed80e072
5 changed files with 102 additions and 3 deletions

30
sh/.config/sh/alias Normal file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env sh
#
# Global aliases for any shell
# Avoid aliases which I did not create -- unalias EVERYTHING
unalias -a
# v shorthand for neovim
alias v="nvim"
# exit shell mimicks vim
alias :q="exit"
# ls defaults
if [ "$(uname -s)" = "Linux" ]; then
# we're on linux
alias l="ls -lhF"
alias L="ls -lAhF"
fi
# cd defaults
alias ..="cd .."
alias ...="cd ../.."
alias ~="cd ~"
# clear my screen
alias cl="clear"
# Display your current external ip address
alias myip="curl -s icanhazip.com"

17
sh/.config/sh/env Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env sh
#
# Set global environment variables
# Load XDG specifications
# shellcheck source=xdg
[ -f ~/.config/sh/xdg ] && . ~/.config/sh/xdg
# anything on BIN_HOME should be executable form anywhere
export PATH="$PATH:$XDG_BIN_HOME"
###############################
## BEGIN GLOBAL ENV VARS ##
###############################
# if we forgot to set it treat bash as default
export SHELL=${SHELL:-/bin/bash}

18
sh/.config/sh/profile Normal file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env sh
#
# Is executed for any base sh login-shell
# Bash only executes when neither bash-profile nor bashrc exist
# (will only load the first one it finds)
#
# see https://github.com/rbenv/rbenv/wiki/unix-shell-initialization
## Load all global environmment variables
# shellcheck source=env
[ -f ~/.config/sh/env ] && . ~/.config/sh/env
# load additional packages
if [ -d "$XDG_CONFIG_HOME/sh/env.d" ]; then
for _env in "$XDG_CONFIG_HOME/sh/env.d"/*.sh; do
. "$_env"
done
unset _env
fi

33
sh/.config/sh/xdg Normal file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env sh
# XDG Base Directory Specification
#
# Sets up necessary environment variables for XDG convention,
# and those that applications obey for their environments.
#
# Thank you remeberYou for the idea
# see: https://github.com/rememberYou/dotfiles/blob/master/sh/.config/sh/xdg
#
# Additionally, home directories are set using the XDG specification,
# if the xdg-user-dirs module is enabled.
#
# Shellcheck will complain about setting permissions for the directories
# unless it is ignored https://github.com/koalaman/shellcheck/wiki/SC2174
# shellcheck disable=SC2174
# http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
test "$XDG_CACHE_HOME" || export XDG_CACHE_HOME="$HOME/.cache"
test "$XDG_CONFIG_HOME" || export XDG_CONFIG_HOME="$HOME/.config"
test "$XDG_DATA_HOME" || export XDG_DATA_HOME="$HOME/.local/share"
test "$XDG_LIB_HOME" || export XDG_LIB_HOME="$HOME/.local/lib"
## Non-Standard additions
# non-standard, is added to path to enable execution of any files herein
test "$XDG_BIN_HOME" || export XDG_BIN_HOME="$HOME/.local/bin"
## ensure directories exist
test -d "$XDG_BIN_HOME" || mkdir -p -m 0700 "$XDG_BIN_HOME"
test -d "$XDG_CACHE_HOME" || mkdir -p -m 0700 "$XDG_CACHE_HOME"
test -d "$XDG_CONFIG_HOME" || mkdir -p -m 0700 "$XDG_CONFIG_HOME"
test -d "$XDG_DATA_HOME" || mkdir -p -m 0700 "$XDG_DATA_HOME"
test -d "$XDG_LIB_HOME" || mkdir -p -m 0700 "$XDG_LIB_HOME"

View file

@ -6,10 +6,11 @@
# absolute path. No other format is supported. # absolute path. No other format is supported.
# #
XDG_DESKTOP_DIR="$HOME/desktop" XDG_DESKTOP_DIR="$HOME/desktop"
XDG_DOWNLOAD_DIR="$HOME/downloads"
XDG_TEMPLATES_DIR="$HOME/templates"
XDG_PUBLICSHARE_DIR="$HOME/public"
XDG_DOCUMENTS_DIR="$HOME/documents" XDG_DOCUMENTS_DIR="$HOME/documents"
XDG_DOWNLOAD_DIR="$HOME/downloads"
XDG_MUSIC_DIR="$HOME/music" XDG_MUSIC_DIR="$HOME/music"
XDG_PICTURES_DIR="$HOME/pictures" XDG_PICTURES_DIR="$HOME/pictures"
XDG_PROJECTS_DIR="$HOME/projects"
XDG_PUBLICSHARE_DIR="$HOME/public"
XDG_TEMPLATES_DIR="$HOME/templates"
XDG_VIDEOS_DIR="$HOME/videos" XDG_VIDEOS_DIR="$HOME/videos"