add-to-path is king
This commit is contained in:
parent
be68302a3b
commit
af44bcd6d3
6 changed files with 50 additions and 47 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
alias aliases="alias | sed 's/=.*//'"
|
||||
alias functions="declare -f | grep '^[a-z].* ()' | sed 's/{$//'"
|
||||
alias paths='echo -e ${PATH//:/\\n}'
|
||||
|
||||
alias reload="source ~/.zshrc"
|
||||
alias rr="rm -rf"
|
||||
|
|
|
@ -20,7 +20,7 @@ if [ -f "$HOME/mambaforge/etc/profile.d/mamba.sh" ]; then
|
|||
fi
|
||||
# <<< conda initialize <<<
|
||||
|
||||
! is-tty && [ -d "$HOME/mambaforge/envs/dev" ] && conda activate dev
|
||||
# ! is-tty && [ -d "$HOME/mambaforge/envs/dev" ] && conda activate dev
|
||||
|
||||
# >>> mamba initialize >>>
|
||||
# !! Contents within this block are managed by 'mamba init' !!
|
||||
|
|
29
lib/env.zsh
29
lib/env.zsh
|
@ -40,9 +40,9 @@ fi
|
|||
|
||||
# Setup fzf
|
||||
# ---------
|
||||
if [[ $PATH != *$HOME/.fzf/bin* ]]; then
|
||||
export PATH="${PATH:+${PATH}:}$HOME/.fzf/bin"
|
||||
fi
|
||||
# if [[ $PATH != *$HOME/.fzf/bin* ]]; then
|
||||
# export PATH="${PATH:+${PATH}:}$HOME/.fzf/bin"
|
||||
# fi
|
||||
# ---------
|
||||
|
||||
# Add lfcd command
|
||||
|
@ -51,11 +51,11 @@ if is-executable lf; then
|
|||
source "$XDG_CONFIG_HOME/lf/lfcd.sh"
|
||||
fi
|
||||
# ----------------
|
||||
|
||||
if is-executable fnm; then
|
||||
eval "$(fnm env)"
|
||||
fi
|
||||
|
||||
#
|
||||
# if is-executable fnm && is-itty; then
|
||||
# eval "$(fnm env)"
|
||||
# fi
|
||||
#
|
||||
if is-executable bat; then
|
||||
export BAT_THEME=Catppuccin
|
||||
export BAT_STYLE=header,numbers,grid
|
||||
|
@ -98,17 +98,19 @@ fi
|
|||
|
||||
# pnpm
|
||||
export PNPM_HOME="$HOME/.local/share/pnpm"
|
||||
export PATH="$PNPM_HOME:$PATH"
|
||||
# pnpm end
|
||||
# export PATH="$PNPM_HOME:$PATH"
|
||||
add-to-path prepend "$PNPM_HOME:$PATH"
|
||||
|
||||
if [ -d "$HOME/.pkgs/google-cloud-sdk" ]; then
|
||||
source "$HOME/.pkgs/google-cloud-sdk/completion.zsh.inc"
|
||||
source "$HOME/.pkgs/google-cloud-sdk/path.zsh.inc"
|
||||
# source "$HOME/.pkgs/google-cloud-sdk/path.zsh.inc"
|
||||
add-to-path prepend "$HOME/.pkgs/google-cloud-sdk/bin"
|
||||
fi
|
||||
|
||||
if [ -d "$HOME/.deno" ]; then
|
||||
export DENO_INSTALL="$HOME/.deno"
|
||||
export PATH="$DENO_INSTALL/bin:$PATH"
|
||||
# export PATH="$DENO_INSTALL/bin:$PATH"
|
||||
add-to-path prepend "$DENO_INSTALL/bin:$PATH"
|
||||
fi
|
||||
|
||||
if [ -d "$HOME/.bun" ]; then
|
||||
|
@ -117,5 +119,6 @@ if [ -d "$HOME/.bun" ]; then
|
|||
|
||||
# bun
|
||||
export BUN_INSTALL="$HOME/.bun"
|
||||
export PATH="$BUN_INSTALL/bin:$PATH"
|
||||
# export PATH="$BUN_INSTALL/bin:$PATH"
|
||||
add-to-path prepend "$BUN_INSTALL/bin:$PATH"
|
||||
fi
|
||||
|
|
|
@ -84,3 +84,25 @@ format-qmd() {
|
|||
# TODO: add support for outputs
|
||||
jupytext --from qmd $1 --pipe black --opt 'notebook_metadata_filter=-all'
|
||||
}
|
||||
|
||||
add-to-path () {
|
||||
# $1 prepend/append
|
||||
# $2 path
|
||||
! [[ -d "$2" ]] && return 0
|
||||
case ":$PATH:" in
|
||||
*":$2:"*) :;; # already there
|
||||
*)
|
||||
if [[ "$1" == 'prepend' ]]; then
|
||||
PATH="$2:$PATH"
|
||||
elif [[ "$1" == 'append' ]]; then
|
||||
PATH="$PATH:$2"
|
||||
else
|
||||
echo "please specify append/prepend not $1"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
print-paths() {
|
||||
sed 's/:/\n/g' <<< "$PATH"
|
||||
}
|
||||
|
|
42
lib/path.zsh
42
lib/path.zsh
|
@ -1,37 +1,15 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
# TODO: Refactor this entire mess
|
||||
add-to-path prepend "/bin"
|
||||
add-to-path prepend "/usr/bin"
|
||||
add-to-path prepend "/usr/local/bin"
|
||||
|
||||
# Start with system path
|
||||
# Retrieve it from getconf, otherwise it's just current $PATH
|
||||
prepend-path() {
|
||||
[ -d $1 ] && PATH="$1:$PATH"
|
||||
}
|
||||
|
||||
#is-executable getconf && PATH=$($(command -v getconf) PATH)
|
||||
|
||||
# Prepend new items to path (if directory exists)
|
||||
prepend-path "/bin"
|
||||
prepend-path "/usr/bin"
|
||||
prepend-path "/usr/local/bin"
|
||||
|
||||
PATH="$DOTFILES_DIR/bin:$PATH"
|
||||
PATH="$HOME/bin:$PATH"
|
||||
PATH="$HOME/.local/bin:$PATH"
|
||||
PATH="$HOME/.cargo/bin:$PATH"
|
||||
PATH="$PATH:/usr/local/go/bin"
|
||||
PATH="/usr/local/texlive/2021/bin/x86_64-linux:$PATH"
|
||||
PATH="$HOME/go/bin:$PATH"
|
||||
PATH="$HOME/.extra/bin:$PATH"
|
||||
|
||||
# Remove duplicates (preserving prepended items)
|
||||
# Source: http://unix.stackexchange.com/a/40755
|
||||
|
||||
PATH=$(echo -n $PATH | awk -v RS=: '{ if (!arr[$0]++) {printf("%s%s",!ln++?"":":",$0)}}')
|
||||
PATH="$(perl -e 'print join(":", grep { not $seen{$_}++ } split(/:/, $ENV{PATH}))')"
|
||||
|
||||
# PATH=$(printf %s "$PATH" |
|
||||
# awk -vRS=: -vORS= '!a[$0]++ {if (NR>1) printf(":"); printf("%s", $0) }')
|
||||
# # Wrap up
|
||||
# home paths
|
||||
paths=("bin" ".local/bin" ".cargo/bin" "go/bin" ".extra/bin")
|
||||
for directory in "${paths[@]}"; do
|
||||
add-to-path prepend "$HOME/$directory"
|
||||
done
|
||||
|
||||
export PATH
|
||||
|
||||
|
||||
|
|
|
@ -31,4 +31,5 @@ zstyle ':completion::complete:make:*:targets' call-command true
|
|||
|
||||
is-executable fzf && source $DOTFILES_DIR/lib/fzf.zsh
|
||||
|
||||
# TODO: make this fail for both no-atuin and no is-tty
|
||||
is-executable atuin && is-tty || eval "$(atuin init zsh)"
|
||||
|
|
Loading…
Reference in a new issue