Improvements
This commit is contained in:
parent
d8e37c1fdf
commit
d6a9f59544
|
@ -1,15 +1,28 @@
|
||||||
|
ANSI_Print() { printf "\E[${ANSI_Code}m%s\E[0m" "$@"; }
|
||||||
|
ANSI_Red() { ANSI_Code=31 ANSI_Print "$@"; }
|
||||||
|
ANSI_Green() { ANSI_Code=32 ANSI_Print "$@"; }
|
||||||
|
ANSI_Yellow() { ANSI_Code=33 ANSI_Print "$@"; }
|
||||||
|
ANSI_Blue() { ANSI_Code=34 ANSI_Print "$@"; }
|
||||||
|
ANSI_Indiego() { ANSI_Code=35 ANSI_Print "$@"; }
|
||||||
|
ANSI_Cyan() { ANSI_Code=36 ANSI_Print "$@"; }
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
(>&2 printf '\E[34mWARNING:\E[0m %s\n' "$@" )
|
(>&2 printf '%s %s\n' $(ANSI_Yellow 'WARNING:') "$(echo "$@")" )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The way to call this is:
|
||||||
|
# eval $(error 1 "message") || exit $?
|
||||||
|
# where 1 is the return/exit code and "message" is the message to be
|
||||||
|
# displayed
|
||||||
error() {
|
error() {
|
||||||
(>&2 printf '\E[31mERROR:\E[0m %s\n' "$@" )
|
printf "(>&2 \
|
||||||
|
printf '%%s %%b' '$(ANSI_Red 'ERROR:')' '$(printf "%b " "${@:2}")') \
|
||||||
|
&& echo '' && return ${1} 2>/dev/null || exit ${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
require_root() {
|
require_root() {
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
error "This script should only be run using sudo or as the root user"
|
eval $(error 1 "This script should only be run using sudo or as the root user")
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +35,13 @@ recommend_root() {
|
||||||
|
|
||||||
function setacl() {
|
function setacl() {
|
||||||
if [[ $# -lt 4 ]]; then
|
if [[ $# -lt 4 ]]; then
|
||||||
error "setacl missing arguments, called with '$1' ${@:2}"
|
eval $(error 1 \
|
||||||
printf "%s\n" "Usage:" "\tsetacl <Options> <Ownership> <Permissions> <Path> [<Additional Paths>...]"
|
"setacl missing arguments, called with '$1' ${@:2}" \
|
||||||
|
$(printf "%s\n" \
|
||||||
|
"Usage:" \
|
||||||
|
"\tsetacl <Options> <Ownership> <Permissions> <Path> [<Additional Paths>...]" \
|
||||||
|
)
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local Options=${1}
|
local Options=${1}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#alias sudo="/usr/bin/sudo "
|
#alias sudo="/usr/bin/sudo "
|
||||||
|
alias _sudo="env sudo "
|
||||||
function sudo() {
|
function sudo() {
|
||||||
local cli="$(command -v "${1}")"
|
local cli="$(command -v "${1}")"
|
||||||
[[ -x "$cli" ]] || cli="${1}"
|
[[ -x "$cli" ]] || cli="${1}"
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
if [[ -z "$(which-command chezmoi)" && -x "$HOME/bin/chezmoi" ]]; then
|
||||||
|
function chezmoi() {
|
||||||
|
"$HOME/bin/chezmoi" "${@}"
|
||||||
|
}
|
||||||
|
fi
|
||||||
if [[ -n "$(which-command chezmoi)" ]]; then
|
if [[ -n "$(which-command chezmoi)" ]]; then
|
||||||
export CHEZMOIROOT="$(chezmoi source-path)"
|
export CHEZMOIROOT="$(chezmoi source-path)"
|
||||||
export CZ="$CHEZMOIROOT"
|
export CZ="$CHEZMOIROOT"
|
||||||
|
@ -21,7 +26,7 @@ if [[ -n "$(which-command chezmoi)" ]]; then
|
||||||
alias czu="cz upgrade && cz update && exec $SHELL "
|
alias czu="cz upgrade && cz update && exec $SHELL "
|
||||||
alias czxu="cz upgrade && cz update && czx apply && exec $SHELL "
|
alias czxu="cz upgrade && cz update && czx apply && exec $SHELL "
|
||||||
|
|
||||||
alias cz-refresh="czs | cut -d\ -f2 | grep '^\.sz\.shrc\.d' | xargs cz forget --force; cz add ~/.sz.shrc.d --recursive; cz status; cz git status"
|
alias cz-refresh="czs | cut -d\ -f2 | grep '^\.sz\.shrc\.d' | xargs chezmoi forget --force; cz add ~/.sz.shrc.d --recursive; cz status; cz git status"
|
||||||
alias cz-commit="cz git -- commit -a "
|
alias cz-commit="cz git -- commit -a "
|
||||||
|
|
||||||
function cz-remove-missing() {
|
function cz-remove-missing() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
if [[ -n "$(which-command oh-my-posh)" ]]; then
|
if [[ -n "$(which-command oh-my-posh)" ]]; then
|
||||||
OHMYPOSH_CONFIG=''
|
OHMYPOSH_CONFIG=''
|
||||||
[[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="--config ~/.poshtheme.omp.json"
|
[[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="~/.poshtheme.omp.json"
|
||||||
eval "$(oh-my-posh init bash $OHMYPOSH_CONFIG)"
|
eval "$(oh-my-posh init bash --config $OHMYPOSH_CONFIG)"
|
||||||
unset OHMYPOSH_CONFIG
|
unset OHMYPOSH_CONFIG
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
alias which-command="type -fP "
|
|
||||||
function which-command() {
|
function which-command() {
|
||||||
|
local ANSWER=$(type -t "${@}") || return $?
|
||||||
|
[[ $ANSWER == "function" ]] && printf "function " && type "${@}" | tail +2 && return
|
||||||
|
[[ $ANSWER == "alias" ]] && {
|
||||||
|
alias "${@}"
|
||||||
|
}
|
||||||
type -fP "${@}"
|
type -fP "${@}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1,9 @@
|
||||||
alias which-command="whence "
|
function which-command() {
|
||||||
|
local ANSWER=$(whence -w "${@}") || return $?
|
||||||
|
ANSWER=${ANSWER##*: }
|
||||||
|
[[ $ANSWER == "function" ]] && printf "function " && whence -f "${@}" && return
|
||||||
|
[[ $ANSWER == "alias" ]] && {
|
||||||
|
alias "${@}"
|
||||||
|
}
|
||||||
|
whence "${@}"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue