feat: x-path-* as scripts, run other changes

This commit is contained in:
2023-11-01 14:45:03 +02:00
parent cec1edb269
commit 4572c42eea
12 changed files with 109 additions and 110 deletions

View File

@@ -18,6 +18,12 @@ export XDG_BIN_HOME="$HOME/.local/bin"
export XDG_CACHE_HOME="$HOME/.cache" export XDG_CACHE_HOME="$HOME/.cache"
export XDG_RUNTIME_DIR="$HOME/.local/run" export XDG_RUNTIME_DIR="$HOME/.local/run"
source "$DOTFILES/config/exports"
# shellcheck source=../config/fzf/fzf.bash
[ -f "${DOTFILES}/config/fzf/fzf.bash" ] &&
source "${DOTFILES}/config/fzf/fzf.bash"
# Import ssh keys in keychain # Import ssh keys in keychain
ssh-add -A 2>/dev/null ssh-add -A 2>/dev/null
@@ -96,5 +102,3 @@ export OSH="$HOME/.local/share/oh-my-bash"
# export EDITOR='mvim' # export EDITOR='mvim'
# fi # fi
} }

View File

@@ -16,3 +16,4 @@ export XDG_BIN_HOME="$HOME/.local/bin"
export XDG_CACHE_HOME="$HOME/.cache" export XDG_CACHE_HOME="$HOME/.cache"
export XDG_RUNTIME_DIR="$HOME/.local/run" export XDG_RUNTIME_DIR="$HOME/.local/run"
source "$DOTFILES/config/exports"

View File

@@ -1,6 +1,12 @@
# this is my zsh config. there are many like it, but this one is mine. # this is my zsh config. there are many like it, but this one is mine.
# shellcheck shell=bash # shellcheck shell=bash
export PATH="$HOME/.local/bin:$HOME/.dotfiles/local/bin:$HOME/.local/go/bin:$PATH"
source "$DOTFILES/config/exports"
source "$DOTFILES/config/alias"
source "$DOTFILES/config/functions"
source "$DOTFILES/scripts/shared.sh" source "$DOTFILES/scripts/shared.sh"
export COMPLETION_WAITING_DOTS=true export COMPLETION_WAITING_DOTS=true
@@ -17,11 +23,6 @@ path_prepend "$XDG_BIN_HOME"
path_prepend "$HOME/.local/go/bin" path_prepend "$HOME/.local/go/bin"
path_prepend "$XDG_DATA_HOME/bob/nvim-bin" path_prepend "$XDG_DATA_HOME/bob/nvim-bin"
source "$DOTFILES/config/exports-shell"
source "$DOTFILES/config/exports-apps"
source "$DOTFILES/config/alias"
source "$DOTFILES/config/functions"
export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion" export ZSH_CUSTOM_COMPLETION_PATH="$XDG_CONFIG_HOME/zsh/completion"
x-dc "$ZSH_CUSTOM_COMPLETION_PATH" x-dc "$ZSH_CUSTOM_COMPLETION_PATH"

View File

@@ -6,9 +6,9 @@ DOTFILES="$HOME/.dotfiles"
# Get installed php versions from brew and setup aliases # Get installed php versions from brew and setup aliases
function x-set-php-aliases function x-set-php-aliases
{ {
have brew && { x-have brew && {
local php_versions=() local php_versions=()
while IFS="" read -r line; do php_versions+=("$line"); done < <(brew_installed | grep '^php') while IFS="" read -r line; do php_versions+=("$line"); done < <(bkt -- brew list | grep '^php')
php_error_reporting='-d error_reporting=22527' php_error_reporting='-d error_reporting=22527'
@@ -61,8 +61,8 @@ alias please="sudo "
# Color the grep output # Color the grep output
alias grep='grep --color' alias grep='grep --color'
! have eza && alias ls='ls --color=auto' ! x-have eza && alias ls='ls --color=auto'
have eza && { x-have eza && {
alias ls='eza -h -s=type --git --icons --group-directories-first' alias ls='eza -h -s=type --git --icons --group-directories-first'
} }

View File

@@ -2,7 +2,57 @@
# shellcheck shell=bash # shellcheck shell=bash
# vim: filetype=zsh # vim: filetype=zsh
# Cache commands using bkt if installed
if command -v bkt >&/dev/null; then
bkt()
{
command bkt --cache-dir="$XDG_CACHE_HOME/bkt" "$@"
}
else
# If bkt isn't installed skip its arguments and just execute directly.
# Optionally write a msg to stderr suggesting users install bkt.
bkt()
{
while [[ "$1" == --* ]]; do shift; done
"$@"
}
fi
# shorthand for checking if the system has the bin in path,
# this version does not use caching
# usage: have_command php && php -v
function have_command
{
command -v "$1" >&/dev/null
}
# shorthand for checking if the system has the bin in path,
# this version uses caching
# usage: have php && php -v
function have
{
bkt -- which "$1" >&/dev/null
}
function brew_installed
{
bkt -- brew list
}
# shorthand for checking if brew package is installed
# usage: have_brew php && php -v
function have_brew
{
! have brew && return 125
if bkt -- brew list "$1" &> /dev/null; then
return 0
else
return 1
fi
}
source "$DOTFILES/config/exports-shell" source "$DOTFILES/config/exports-shell"
source "$DOTFILES/config/exports-apps" source "$DOTFILES/config/exports-apps"
have nvim && export EDITOR="nvim" x-have nvim && export EDITOR="nvim"

View File

@@ -21,15 +21,15 @@ x-dc "$ANSIBLE_GALAXY_CACHE_DIR"
export ANDROID_HOME="$XDG_DATA_HOME/android" export ANDROID_HOME="$XDG_DATA_HOME/android"
# bob manages nvim versions # bob manages nvim versions
path_prepend "$XDG_DATA_HOME/bob/nvim-bin" x-path-prepend "$XDG_DATA_HOME/bob/nvim-bin"
have nvim && export EDITOR="nvim" x-have nvim && export EDITOR="nvim"
export HOMEBREW_NO_ENV_HINTS=true export HOMEBREW_NO_ENV_HINTS=true
# composer, https://getcomposer.org/ # composer, https://getcomposer.org/
export COMPOSER_HOME="$XDG_STATE_HOME/composer" export COMPOSER_HOME="$XDG_STATE_HOME/composer"
export COMPOSER_BIN="$COMPOSER_HOME/vendor/bin" export COMPOSER_BIN="$COMPOSER_HOME/vendor/bin"
path_append "$COMPOSER_BIN" x-path-append "$COMPOSER_BIN"
# docker, https://docs.docker.com/engine/reference/commandline/cli/ # docker, https://docs.docker.com/engine/reference/commandline/cli/
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker" export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
@@ -39,7 +39,7 @@ export DOCKER_SCAN_SUGGEST=false
# ffmpeg # ffmpeg
export FFMPEG_DATADIR="$XDG_CONFIG_HOME/ffmpeg" export FFMPEG_DATADIR="$XDG_CONFIG_HOME/ffmpeg"
have ffmpeg && x-dc "$FFMPEG_DATADIR" x-have ffmpeg && x-dc "$FFMPEG_DATADIR"
# GnuPG # GnuPG
export GNUPGHOME="$XDG_DATA_HOME/gnupg" export GNUPGHOME="$XDG_DATA_HOME/gnupg"
@@ -53,14 +53,14 @@ export NBRC_PATH="$XDG_CONFIG_HOME/nbrc"
export NB_DIR="$XDG_STATE_HOME/nb" export NB_DIR="$XDG_STATE_HOME/nb"
# NPM: Add npm packages to path # NPM: Add npm packages to path
have node && { x-have node && {
NVM_NODE_BIN_DIR="$(dirname "$(which node)")" NVM_NODE_BIN_DIR="$(dirname "$(which node)")"
path_append "$NVM_NODE_BIN_DIR" x-path-append "$NVM_NODE_BIN_DIR"
} }
# op (1Password cli) is present # op (1Password cli) is present
export OP_CACHE="$XDG_STATE_HOME/1password" export OP_CACHE="$XDG_STATE_HOME/1password"
have op && { x-have op && {
[ "$DOTFILES_CURRENT_SHELL" = "zsh" ] && { [ "$DOTFILES_CURRENT_SHELL" = "zsh" ] && {
eval "$(op completion zsh)" eval "$(op completion zsh)"
compdef _op op compdef _op op
@@ -72,8 +72,8 @@ have op && {
# pyenv, python environments # pyenv, python environments
export WORKON_HOME="$XDG_DATA_HOME/virtualenvs" export WORKON_HOME="$XDG_DATA_HOME/virtualenvs"
export PYENV_ROOT="$XDG_STATE_HOME/pyenv" export PYENV_ROOT="$XDG_STATE_HOME/pyenv"
have pyenv && { x-have pyenv && {
path_append "$PYENV_ROOT/shims" x-path-append "$PYENV_ROOT/shims"
eval "$(pyenv init -)" eval "$(pyenv init -)"
} }
@@ -87,8 +87,8 @@ export BUNDLE_USER_CACHE="$XDG_CACHE_HOME"/bundle
export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME"/bundle export BUNDLE_USER_PLUGIN="$XDG_DATA_HOME"/bundle
export RBENV_ROOT="$XDG_STATE_HOME/rbenv" export RBENV_ROOT="$XDG_STATE_HOME/rbenv"
x-dc "$RBENV_ROOT" x-dc "$RBENV_ROOT"
have gem && path_append "${GEM_HOME}/bin" x-have gem && x-path-append "${GEM_HOME}/bin"
have rbenv && { x-have rbenv && {
[ "$DOTFILES_CURRENT_SHELL" = "zsh" ] && eval "$(rbenv init - zsh)" [ "$DOTFILES_CURRENT_SHELL" = "zsh" ] && eval "$(rbenv init - zsh)"
[ "$DOTFILES_CURRENT_SHELL" = "bash" ] && eval "$(rbenv init - bash)" [ "$DOTFILES_CURRENT_SHELL" = "bash" ] && eval "$(rbenv init - bash)"
} }
@@ -96,7 +96,7 @@ have rbenv && {
# Rust / cargo # Rust / cargo
export RUSTUP_HOME="$XDG_DATA_HOME/rustup" export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
export CARGO_HOME="$XDG_DATA_HOME/cargo" export CARGO_HOME="$XDG_DATA_HOME/cargo"
path_append "$CARGO_HOME/bin" x-path-append "$CARGO_HOME/bin"
# screen # screen
export SCREENRC="$XDG_CONFIG_HOME/misc/screenrc" export SCREENRC="$XDG_CONFIG_HOME/misc/screenrc"

View File

@@ -54,32 +54,3 @@ export GREP_OPTIONS="--color=auto"
# update the values of LINES and COLUMNS. # update the values of LINES and COLUMNS.
hash shopt 2> /dev/null && shopt -s checkwinsize hash shopt 2> /dev/null && shopt -s checkwinsize
# Set dircolors based on the file, if it exists
have dircolors && eval $(dircolors "$XDG_CONFIG_HOME/dircolors")
# If we are using zsh, color our dir lists and such
if [ "$DOTFILES_CURRENT_SHELL" = "-zsh" ]; then
[[ $ZSH_VERSION != "" ]] && {
autoload -U colors zsh/terminfo compinit
colors
compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"
x-dc "$XDG_CACHE_HOME/zsh"
x-dc "$XDG_STATE_HOME/zsh"
export HISTFILE="$XDG_STATE_HOME/zsh/history"
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache"
zstyle ':completion:*' list-colors "$LS_COLORS"
# Load iterm2 shell integration
# https://iterm2.com/documentation-shell-integration.html
[[ -f "$XDG_BIN_HOME/iterm2_shell_integration.zsh" ]] \
&& source "$XDG_BIN_HOME/iterm2_shell_integration.zsh"
}
fi
# If we are using bash
if [ "$DOTFILES_CURRENT_SHELL" = "bash" ]; then
# shellcheck source=../config/fzf/fzf.bash
[ -f "${DOTFILES}/config/fzf/fzf.bash" ] &&
source "${DOTFILES}/config/fzf/fzf.bash"
fi

View File

@@ -3,7 +3,7 @@
which "$1" >&/dev/null which "$1" >&/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo 0 exit 0
else else
echo 1 exit 1
fi fi

8
local/bin/x-path-append Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#
# Add a directory to the beginning of the PATH if it's not already there.
# Usage: x-path-append <dir>
x-path-remove "$1"
export PATH="${PATH:+"$PATH:"}$1"

7
local/bin/x-path-prepend Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
#
# Add a directory to the front of the PATH if it exists and is not already there
# Usage: x-path-prepend <dir>
export PATH="$1${PATH:+":$PATH"}"

7
local/bin/x-path-remove Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
#
# Remove a directory from the PATH
# Usage: x-path-remove <dir>
export PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$1\"" | sed 's/:$//')

View File

@@ -31,23 +31,23 @@ export XDG_RUNTIME_DIR="$HOME/.local/run"
# usage: path_remove ~/.local/bin # usage: path_remove ~/.local/bin
function path_remove function path_remove
{ {
PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$1\"" | sed 's/:$//') x-path-remove "$1"
} }
# Append directory to the PATH # Append directory to the PATH
# usage: path_append ~/.local/bin # usage: path_append ~/.local/bin
function path_append function path_append
{ {
path_remove "$1" x-path-remove "$1"
PATH="${PATH:+"$PATH:"}$1" x-path-prepend "$1"
} }
# Prepend directory to the PATH # Prepend directory to the PATH
# usage: path_prepend ~/.local/bin # usage: path_prepend ~/.local/bin
function path_prepend function path_prepend
{ {
path_remove "$1" x-path-remove "$1"
PATH="$1${PATH:+":$PATH"}" x-path-prepend "$1"
} }
# Create directory if it doesn't exist already # Create directory if it doesn't exist already
@@ -84,56 +84,6 @@ nonascii()
LC_ALL=C grep -n '[^[:print:][:space:]]' "${@}" LC_ALL=C grep -n '[^[:print:][:space:]]' "${@}"
} }
# Cache commands using bkt if installed
if command -v bkt >&/dev/null; then
bkt()
{
command bkt --cache-dir="$XDG_CACHE_HOME/bkt" "$@"
}
else
# If bkt isn't installed skip its arguments and just execute directly.
# Optionally write a msg to stderr suggesting users install bkt.
bkt()
{
while [[ "$1" == --* ]]; do shift; done
"$@"
}
fi
# shorthand for checking if the system has the bin in path,
# this version does not use caching
# usage: have_command php && php -v
function have_command
{
command -v "$1" >&/dev/null
}
# shorthand for checking if the system has the bin in path,
# this version uses caching
# usage: have php && php -v
function have
{
bkt -- which "$1" >&/dev/null
}
function brew_installed
{
bkt -- brew list
}
# shorthand for checking if brew package is installed
# usage: have_brew php && php -v
function have_brew
{
! have brew && return 125
if bkt -- brew list "$1" &> /dev/null; then
return 0
else
return 1
fi
}
CONFIG_PATH="$DOTFILES/config" CONFIG_PATH="$DOTFILES/config"
# Load the shell dotfiles, and then some: # Load the shell dotfiles, and then some: