1
0
dotfiles/.config/zsh/env.zsh

97 lines
2.0 KiB
Bash
Raw Normal View History

2021-03-21 18:25:10 +03:00
#!/bin/zsh
## sort-n-fill PATH
2024-07-10 12:09:31 +03:00
z-sort-path() {
2022-07-19 02:41:45 +03:00
local -a p
2021-03-21 18:25:10 +03:00
local -aU t npath games
2024-02-23 21:46:04 +03:00
p=( ${path} )
2022-07-19 02:41:45 +03:00
2021-03-21 18:25:10 +03:00
## strip "games" first :)
t=( ${(@)p:#*games*} )
games+=( ${(@)p:|t} )
p=( $t )
## process in-home part
t=( ${(@)p:#${HOME}/*} )
2024-01-27 00:10:58 +03:00
npath+=( "${ZSHU[d_scripts]}" "${ZSHU[d_bin]}" "${HOME}/bin" )
2021-03-21 18:25:10 +03:00
npath+=( ${(@)p:|t} )
p=( $t )
## process /usr/local/*
t=( ${(@)p:#/usr/local/*} )
npath+=( /usr/local/sbin /usr/local/bin )
npath+=( ${(@)p:|t} )
p=( $t )
## process /usr/*
t=( ${(@)p:#/usr/*} )
npath+=( /usr/sbin /usr/bin )
npath+=( ${(@)p:|t} )
p=( $t )
## now we're with /sbin and /bin... probably :)
2024-07-10 12:09:31 +03:00
## in case of merged /usr
[ -h /sbin ] || npath+=( /sbin )
[ -h /bin ] || npath+=( /bin )
2021-03-21 18:25:10 +03:00
npath+=( $p )
## finally... games! xD
npath+=( /usr/local/games /usr/games )
2024-02-23 21:46:04 +03:00
npath+=( ${games} )
2021-03-21 18:25:10 +03:00
2024-02-23 21:46:04 +03:00
path=( ${npath} )
2021-03-21 18:25:10 +03:00
hash -f
}
2024-07-10 12:09:31 +03:00
z-sort-path
2021-03-21 18:25:10 +03:00
unset GREP_OPTIONS
unset LS_OPTIONS
unset LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
unset LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION
2021-05-10 12:59:36 +03:00
export LANG=C.UTF-8
2021-03-21 18:25:10 +03:00
export LC_ALL=C.UTF-8
z-set-tmpdir() {
TMPDIR="$1"
TMP="$1"
TEMPDIR="$1"
TEMP="$1"
export TMPDIR TMP TEMPDIR TEMP
}
z-set-tmpdir "${TMPDIR:=/tmp}"
ZSHU[uname]=$(uname -s 2>/dev/null)
ZSHU[uname]=${ZSHU[uname]:l}
ZSHU[mach]=$(uname -m 2>/dev/null)
ZSHU[mach]=${ZSHU[mach]:l}
case "${ZSHU[mach]}" in
2024-01-27 00:10:58 +03:00
amd64 ) ZSHU[mach]=x86_64 ;;
arm64 ) ZSHU[mach]=aarch64 ;;
armv* ) ZSHU[mach]=arm ;;
2021-03-21 18:25:10 +03:00
esac
ZSHU[os_type]=${OSTYPE:l}
ZSHU[os_family]=${ZSHU[uname]:l}
case "${ZSHU[os_family]}" in
2024-01-27 00:10:58 +03:00
*bsd ) ZSHU[os_family]=bsd ;;
2021-03-21 18:25:10 +03:00
esac
ZSHU[host_name]=${(%):-%m}
ZSHU[host_fqdn]=${(%):-%M}
ZSHU[host]=${ZSHU[host_name]}
function {
[ "${ZSHU[uname]}" = darwin ] || return
ZSHU[host]=$(scutil --get ComputerName 2>/dev/null) && return
## last resort
ZSHU[host]=${ZSHU[host_name]}
}
2024-03-04 15:35:55 +03:00
case "${ZSHU[os_family]}" in
linux ) ZSHU[procfs]=/proc ;;
esac