Shell/scripts: Use .addpath_local and add .startup.sh

- Remove bin in .addpath because ~/bin is always at the top, and it will
  automatically get added in parse_addpath

- Put parsing of .addpath_local in parse_addpath instead of in fish
  setup script so that it can be shared in .startup.sh

- Add .startup.sh for init code for non-fish (but ideally posix like)
  shell.
This commit is contained in:
Hedy Li 2021-10-01 12:19:54 +08:00
parent 938877a70d
commit 81037d7978
Signed by: hedy
GPG Key ID: B51B5A8D1B176372
4 changed files with 41 additions and 19 deletions

View File

@ -1,4 +1,3 @@
bin
local/bin
.local/bin
.doomemacs/bin

18
.startup.sh Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env sh
# This script should be run at start up by sh-like shells
# This of course does not include fish.
# For fish see ~/dotscripts/setup/fish and ~/.config/fish/config.fish
# Determine current running shell.
# unix.stackexchange.com/questions/71121/ (comment by frostschutz)
CURSHELL="$(sed -re 's/\x0.*//' /proc/$$/cmdline)"
# Add the paths
export PATH="$(~/bin/parse_addpath | sed 's/ /:/g'):$PATH"
# Hook (the) direnv
if ! command -v direnv &> /dev/null; then
# TODO: Ignore if direnv hook retured status 1
eval "$(direnv hook $CURSHELL)"
fi

View File

@ -2,12 +2,23 @@
# read addpath file and return each path
file="${1:-$HOME/.addpath}"
while read line; do
# If the path doesn't begin with / then assume it is relative to $HOME
# Who cares if this is bashism
if [[ ! "$line" == /* ]]; then
line=$HOME/$line
fi
echo -n "$line "
done < "$file"
file="$HOME/.addpath"
paths=
getpaths() {
while read line; do
# If the path doesn't begin with / then assume it is relative to $HOME
# Who cares if this is bashism
if [[ ! "$line" == /* ]]; then
line=$HOME/$line
fi
echo -n "$line "
done < "$1"
}
paths="$(getpaths $file)"
if [ -f "${file}_local" ]; then
paths="$(getpaths ${file}_local) $paths"
fi
paths="$HOME/bin $paths"
echo "$paths"

View File

@ -3,7 +3,7 @@
PATH=~/bin:$PATH
setpaths() {
fish -c 'set -Ux fish_user_paths $fish_user_paths '"$(parse_addpath $1)"
fish -c 'set -Ux fish_user_paths $fish_user_paths '"$(parse_addpath)"
}
if ! command -v fish &> /dev/null; then
@ -13,16 +13,10 @@ if ! command -v fish &> /dev/null; then
fi
echo "Setting up fish_user_paths..."
fish -c 'set -gx fish_user_paths' # clear the variable first
setpaths ~/.addpath
fish -c 'set -Ux fish_user_paths' # clear the variable first
setpaths
echo "done"
if [ -f ~/.addpath_local ]; then
echo "Adding paths in ~/.addpath_local..."
setpaths ~/.addpath_local
echo "done"
fi
echo Maybe add ~/local/share/man to manpath but I forgot how as of writing
# env