Allow .profile to load multiple config files

• set environment variables in .profile load
 • move bash settings to be in profile if they are for POSIX (sh/zsh/etc)
 • use .d files in bash customizations
main
Buddy Sandidge 4 years ago
parent a3ab0c407f
commit d1090feefe

@ -0,0 +1,7 @@
#shellcheck disable=SC2034
EDITOR=vim
BROWSER=firefox
PATH="${XDG_BIN_HOME}:${PATH}"
HISTCONTROL=ignoredups:erasedups:ignorespace
HISTFILESIZE=
HISTSIZE=

@ -0,0 +1,24 @@
#ft=sh
add_date_prefix () {
DIR=$(dirname "$1")
FILE=$(basename "$1")
DATE=$(date -r "$1" +"%F")
if [ ! -f "$1" ] ; then
echo "unknown file: $1"
return
fi
mv "$1" "$DIR/${DATE}_${FILE}"
}
get_bitrate () {
if [ ! -f "$1" ] ; then
echo "[ERROR] unknown file: $1"
return
fi
if ! command -v exiftool > /dev/null ; then
echo "[ERROR] exiftool not installed"
return
fi
exiftool -AudioBitrate "$1" | awk '{print $4}'
}

@ -1,4 +1,4 @@
#!/usr/bin/env bash #ft=sh
export LANGUAGE="en_US:en" export LANGUAGE="en_US:en"
export LC_MESSAGES="en_US.UTF-8" export LC_MESSAGES="en_US.UTF-8"
@ -10,13 +10,42 @@ export XDG_CACHE_HOME=${XDG_CACHE_HOME:="$HOME/.cache"}
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:="$HOME/.config"} export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:="$HOME/.config"}
export XDG_DATA_HOME=${XDG_DATA_HOME:="$HOME/.local/share"} export XDG_DATA_HOME=${XDG_DATA_HOME:="$HOME/.local/share"}
[[ -f "${XDG_CONFIG_HOME}/user-dirs.dirs" ]] && eval "$( env_file() {
awk '/^XDG_/ {print "export " $1}' "${XDG_CONFIG_HOME}/user-dirs.dirs" file="${1}"
)" if [ ! -f "${file}" ]; then
return
fi
eval "$(
grep -v '^\s*\#' "${file}" |
grep -v '^\s*$' |
sed 's/^\s*export//g' |
sed 's/^/export /g'
)"
}
env_file "${XDG_CONFIG_HOME}/user-dirs.dirs"
if [ -d "${XDG_CONFIG_HOME}/profile/env.d" ]; then
for file in "${XDG_CONFIG_HOME}"/profile/env.d/*.env; do
env_file "${file}"
done
fi
unset env_file
if [ -d "${XDG_CONFIG_HOME}/profile/profile.d" ]; then
for file in "${XDG_CONFIG_HOME}"/profile/profile.d/*.sh; do
if [ -r "$file" ]; then
#shellcheck disable=1090
. "$file"
fi
done
fi
if [[ ${SHELL} = /bin/bash ]] || [[ ${SHELL} = /usr/local/bin/bash ]]; then if [ "${SHELL}" = /bin/bash ] || [ "${SHELL}" = /usr/local/bin/bash ]; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
if [[ -f "${HOME}/.bashrc" ]]; then if [ -f "${HOME}/.bashrc" ]; then
source "${HOME}/.bashrc" . "${HOME}/.bashrc"
fi fi
fi fi

@ -1,56 +1,10 @@
# If not running interactively, don't do anything # If not running interactively, don't do anything
[ -z "$PS1" ] && return [ -z "$PS1" ] && return
function source-file {
local file
file="$1"
if [[ -f "$file" ]]; then
# shellcheck disable=SC1090
source "$file"
fi
}
if [[ ! "${BASH_VERSION}" = "3.2*" ]]; then if [[ -f "${XDG_CONFIG_HOME}/bash/prompt.sh" ]]; then
shopt -s autocd # shellcheck disable=SC1090
fi source "${XDG_CONFIG_HOME}/bash/prompt.sh"
CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/bash"
source-file /etc/bash_completion
source-file "${CONFIG}/environment.sh"
source-file "${CONFIG}/aliases.sh"
source-file "${CONFIG}/functions.sh"
source-file "${CONFIG}/path.sh"
source-file "${CONFIG}/prompt.sh"
source-file "${CONFIG}/completion.sh"
source-file ~/opt/bash/env
unset -f source-file
# append to the history file, don't overwrite it
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# Disable capslock
if [[ -x $(which setxkbmap) ]]; then
if [[ $(uname) == Linux ]]; then
setxkbmap -option ctrl:nocaps
fi
fi
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && (eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)")
fi
if [ "$TERM" == xterm ]; then
export TERM=xterm-256color
fi fi
if [ -d "${XDG_CONFIG_HOME}"/bash/bashrc.d ]; then if [ -d "${XDG_CONFIG_HOME}"/bash/bashrc.d ]; then

@ -1,3 +1,4 @@
#ft=bash
alias ll='ls -alF' alias ll='ls -alF'
alias curl='curl --proto-default https --silent ' alias curl='curl --proto-default https --silent '

@ -0,0 +1,18 @@
#ft=bash
# Disable capslock
if [[ -x $(which setxkbmap) ]] && [[ $(uname) == Linux ]]; then
setxkbmap -option ctrl:nocaps
fi
# make less more friendly for non-text input files, see lesspipe(1)
if [ -x /usr/bin/lesspipe ]; then
eval "$(SHELL=/bin/sh lesspipe)"
fi
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
if test -r ~/.dircolors ; then
eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi
fi

@ -1,5 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ -f /etc/bash_completion ]; then
source /etc/bash_completion
fi
# shellcheck disable=SC1091
if [ -f /usr/local/etc/bash_completion ]; then
source /usr/local/etc/bash_completion
fi
COMPLETION_DIR=/usr/local/etc/bash_completion.d/ COMPLETION_DIR=/usr/local/etc/bash_completion.d/
if [ -d "$COMPLETION_DIR" ]; then if [ -d "$COMPLETION_DIR" ]; then
@ -15,7 +24,4 @@ if [ -d "$COMPLETION_DIR" ]; then
unset i unset i
fi fi
# shellcheck disable=SC1091
[[ -f /usr/local/etc/bash_completion ]] && source /usr/local/etc/bash_completion
unset COMPLETION_DIR unset COMPLETION_DIR

@ -1,6 +1,9 @@
#!/usr/bin/env bash #ft=bash
function min-jpg { function min-jpg {
if ! command -v jpegtran &> /dev/null ; then
echo "jpegtran not installed"
fi
tmpfile="$(mktemp)" tmpfile="$(mktemp)"
ogfile="$1" ogfile="$1"
jpegtran -optimize -perfect -outfile "$tmpfile" "$ogfile" jpegtran -optimize -perfect -outfile "$tmpfile" "$ogfile"
@ -8,6 +11,9 @@ function min-jpg {
} }
function min-png { function min-png {
if ! command -v pngcrush &> /dev/null ; then
echo "pngcrush not installed"
fi
tmpfile="$(mktemp)" tmpfile="$(mktemp)"
ogfile="$1" ogfile="$1"
pngcrush -rem alla -reduce -brute "$ogfile" "$tmpfile" pngcrush -rem alla -reduce -brute "$ogfile" "$tmpfile"
@ -19,12 +25,5 @@ function get-create-date {
} }
function add-date-prefix { function add-date-prefix {
DIR=$(dirname "$1") add_date_prefix "$1" "$2"
FILE=$(basename "$1")
DATE=$(date -r "$1" +"%F")
mv "$1" "$DIR/${DATE}_${FILE}"
}
function get-bitrate {
exiftool -AudioBitrate "$1" | awk '{print $4}'
} }

@ -0,0 +1,11 @@
#ft=bash
if [[ ! "${BASH_VERSION}" = "3.2*" ]]; then
shopt -s autocd
fi
# append to the history file, don't overwrite it
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

@ -0,0 +1,3 @@
#shellcheck disable=SC2034
HISTTIMEFORMAT='%y-%m-%d %T λ '
QUOTING_STYLE=literal

@ -1,13 +0,0 @@
#!/usr/bin/env bash
export EDITOR=vim
export BROWSER=firefox
export HISTCONTROL=ignoredups:erasedups:ignorespace
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT='%y-%m-%d %T λ '
# QUOTING_STYLE so ls does not
export QUOTING_STYLE=literal
export RIPGREP_CONFIG_PATH="${XDG_CONFIG_HOME}/ripgrep/config"

@ -1,38 +0,0 @@
#!/usr/bin/env bash
function add-path {
dir="$1"
if [[ $PATH =~ $dir ]]; then
return
fi
if [[ -d $dir ]]; then
PATH=$dir:$PATH
fi
}
function prefix-path {
dir="$1"
if [[ $PATH =~ $dir ]]; then
return
fi
if [[ -d $dir ]]; then
PATH=$PATH:$dir
fi
}
add-path /usr/local/go/bin
add-path ~/.bin
add-path ~/.cargo/bin
add-path ~/.deno/bin
prefix-path ~/.local/bin
add-path ~/bin
add-path ~/go/bin
add-path ~/opt/bin
# work
add-path ~/.rbenv/shims
add-path /usr/local/opt/mysql-client/bin
add-path ~/google-cloud-sdk/bin/
unset -f add-path
unset -f prefix-path

@ -0,0 +1 @@
PATH="${PATH}:${HOME}/.deno/bin"

@ -0,0 +1,6 @@
if [ -d /usr/local/go/bin ] ; then
PATH="${PATH}:/usr/local/go/bin"
fi
if [ -d "${HOME}/go/bin" ] ; then
PATH="${PATH}:${HOME}/go/bin"
fi

@ -1,5 +1,3 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034 # shellcheck disable=SC2034
BASH_SILENCE_DEPRECATION_WARNING=1 BASH_SILENCE_DEPRECATION_WARNING=1
GOPRIVATE=github.com/HelloTech PATH="${PATH}:${HOME}/.rbenv/shims:/usr/local/opt/mysql-client/bin:${HOME}/google-cloud-sdk/bin"
GO_TEST=gotest

@ -0,0 +1,3 @@
# shellcheck disable=SC2034
GOPRIVATE=github.com/HelloTech
GO_TEST=gotest

@ -0,0 +1,2 @@
#shellcheck disable=SC2034
RIPGREP_CONFIG_PATH="${XDG_CONFIG_HOME}/ripgrep/config"

@ -0,0 +1 @@
PATH="${PATH}:${HOME}/.cargo/bin"
Loading…
Cancel
Save