From 3aed80e07208af32ec1fdde06902f12fe0a9066b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 1 Feb 2020 14:37:16 +0100 Subject: [PATCH] Add basic XDG compliant sh architecture --- sh/.config/sh/alias | 30 +++++++++++++++++++++++++ sh/.config/sh/env | 17 ++++++++++++++ sh/.config/sh/profile | 18 +++++++++++++++ sh/.config/sh/xdg | 33 ++++++++++++++++++++++++++++ xdg-user-dirs/.config/user-dirs.dirs | 7 +++--- 5 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 sh/.config/sh/alias create mode 100644 sh/.config/sh/env create mode 100644 sh/.config/sh/profile create mode 100644 sh/.config/sh/xdg diff --git a/sh/.config/sh/alias b/sh/.config/sh/alias new file mode 100644 index 0000000..cc6d2a4 --- /dev/null +++ b/sh/.config/sh/alias @@ -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" diff --git a/sh/.config/sh/env b/sh/.config/sh/env new file mode 100644 index 0000000..151fc36 --- /dev/null +++ b/sh/.config/sh/env @@ -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} diff --git a/sh/.config/sh/profile b/sh/.config/sh/profile new file mode 100644 index 0000000..afb471a --- /dev/null +++ b/sh/.config/sh/profile @@ -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 diff --git a/sh/.config/sh/xdg b/sh/.config/sh/xdg new file mode 100644 index 0000000..5bb76be --- /dev/null +++ b/sh/.config/sh/xdg @@ -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" diff --git a/xdg-user-dirs/.config/user-dirs.dirs b/xdg-user-dirs/.config/user-dirs.dirs index 0384e6d..e258435 100644 --- a/xdg-user-dirs/.config/user-dirs.dirs +++ b/xdg-user-dirs/.config/user-dirs.dirs @@ -6,10 +6,11 @@ # absolute path. No other format is supported. # 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_DOWNLOAD_DIR="$HOME/downloads" XDG_MUSIC_DIR="$HOME/music" 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"