refactor code and add fallback prompt to zsh
This commit is contained in:
95
install
95
install
@@ -1,30 +1,25 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -o errexit
|
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)
|
||||||
set -o pipefail
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" \
|
|
||||||
|| exit 1
|
|
||||||
readonly SCRIPT_DIR
|
readonly SCRIPT_DIR
|
||||||
readonly PROFILES_DIR="${SCRIPT_DIR}/profiles"
|
readonly PROFILES_DIR=${SCRIPT_DIR}/profiles
|
||||||
readonly -a STOW_ARGS=("--no-folding" "--adopt" "--dir" "${PROFILES_DIR}" "--target" "${HOME}")
|
readonly -a STOW_ARGS=(--no-folding --adopt --dir "${PROFILES_DIR}" --target "${HOME}")
|
||||||
readonly SCRIPT_NAME="${0##*/}"
|
readonly SCRIPT_NAME=${0##*/}
|
||||||
|
|
||||||
print_opt() {
|
print_opt() {
|
||||||
local -r option="$1"
|
local -r option=$1
|
||||||
local -r description="$2"
|
local -r description=$2
|
||||||
printf " %-22s %s\n" "${option}" "${description}"
|
printf " %-22s %s\n" "${option}" "${description}"
|
||||||
}
|
}
|
||||||
|
|
||||||
shell_quote() {
|
shell_quote() {
|
||||||
local -r string="$1"
|
local -r string=$1
|
||||||
printf "'%s'" "${string//'/'\\''}"
|
printf "'%s'" "${string//'/'\\''}"
|
||||||
}
|
}
|
||||||
|
|
||||||
array_contains() {
|
array_contains() {
|
||||||
local -r target_item="$1"; shift
|
local -r target_item=$1; shift
|
||||||
local -a -r array=( "$@" )
|
local -a -r array=("$@")
|
||||||
local item
|
local item
|
||||||
for item in "${array[@]}"; do
|
for item in "${array[@]}"; do
|
||||||
if [[ ${item} == "${target_item}" ]]; then
|
if [[ ${item} == "${target_item}" ]]; then
|
||||||
@@ -35,13 +30,13 @@ array_contains() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
local -r message="$1"
|
local -r message=$1
|
||||||
printf "%s: %b\n" "${SCRIPT_NAME}" "${message}" >&2
|
printf "%s: %b\n" "${SCRIPT_NAME}" "${message}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
invalid_option() {
|
invalid_option() {
|
||||||
local -r option="$1"
|
local -r option=$1
|
||||||
die "invalid option $(shell_quote "${option}")\nTry '${SCRIPT_NAME} --help' for usage."
|
die "invalid option $(shell_quote "${option}")\nTry '${SCRIPT_NAME} --help' for usage."
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +64,7 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_profiles_dir() {
|
require_profiles_dir() {
|
||||||
if [[ ! -d "${PROFILES_DIR}" ]]; then
|
if [[ ! -d ${PROFILES_DIR} ]]; then
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
Error: profiles directory not found: ${PROFILES_DIR}
|
Error: profiles directory not found: ${PROFILES_DIR}
|
||||||
|
|
||||||
@@ -89,18 +84,14 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_args() {
|
parse_args() {
|
||||||
list_profiles=""
|
|
||||||
prune_symlinks=""
|
|
||||||
verbose=""
|
|
||||||
profile=""
|
|
||||||
while (( $# > 0 )); do
|
while (( $# > 0 )); do
|
||||||
case "$1" in
|
case $1 in
|
||||||
-h)
|
-h)
|
||||||
show_general_help
|
show_general_help
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
--help)
|
--help)
|
||||||
if (( $# >= 2 )) && [[ -n $2 ]] && [[ $2 != -* ]]; then
|
if (( $# >= 2 )) && [[ $2 ]] && [[ $2 != -* ]]; then
|
||||||
show_help_topic "$2"
|
show_help_topic "$2"
|
||||||
else
|
else
|
||||||
show_general_help
|
show_general_help
|
||||||
@@ -108,17 +99,17 @@ parse_args() {
|
|||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
--help=*)
|
--help=*)
|
||||||
local -r topic="${1#*=}"
|
local -r topic=${1#*=}
|
||||||
[[ -z ${topic} ]] && show_general_help && exit 0
|
[[ -z ${topic} ]] && show_general_help && exit 0
|
||||||
show_help_topic "${topic}"
|
show_help_topic "${topic}"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
-l|--list-profiles) list_profiles="true"; shift ;;
|
-l|--list-profiles) list_profiles=true; shift ;;
|
||||||
-P|--prune-symlinks) prune_symlinks="true"; shift ;;
|
-P|--prune-symlinks) prune_symlinks=true; shift ;;
|
||||||
-v|--verbose) verbose="true"; shift ;;
|
-v|--verbose) verbose=true; shift ;;
|
||||||
-p|--profile)
|
-p|--profile)
|
||||||
( (( $# < 2 )) || [[ -z "$2" ]] ) && die "--profile requires an argument"
|
( (( $# < 2 )) || [[ -z "$2" ]] ) && die "--profile requires an argument"
|
||||||
profile="$2"
|
profile=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
*) invalid_option "$1" ;;
|
*) invalid_option "$1" ;;
|
||||||
@@ -131,7 +122,7 @@ validate_args() {
|
|||||||
die "options '--list-profiles' and others cannot be used together"
|
die "options '--list-profiles' and others cannot be used together"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n ${profile} ]] && ! array_contains "${profile}" "${PROFILES[@]}"; then
|
if [[ ${profile} ]] && ! array_contains "${profile}" "${PROFILES[@]}"; then
|
||||||
die "profile $(shell_quote "${profile}") cannot be found"
|
die "profile $(shell_quote "${profile}") cannot be found"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -157,8 +148,8 @@ show_general_help() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show_help_topic() {
|
show_help_topic() {
|
||||||
local topic="$1"
|
local topic=$1
|
||||||
case "${topic}" in
|
case ${topic} in
|
||||||
profile)
|
profile)
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
A profile is a directory under 'profiles/' that groups dotfiles to be installed
|
A profile is a directory under 'profiles/' that groups dotfiles to be installed
|
||||||
@@ -183,9 +174,9 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
run_pre_hooks() {
|
run_pre_hooks() {
|
||||||
local -r target_profile="$1"
|
local -r target_profile=$1
|
||||||
for hook in "${PROFILES_DIR}/${target_profile}"/hooks/pre/*; do
|
for hook in "${PROFILES_DIR}/${target_profile}"/hooks/pre/*; do
|
||||||
if [[ -f "${hook}" && -x "${hook}" ]]; then
|
if [[ -f ${hook} && -x ${hook} ]]; then
|
||||||
echo "Running pre-install hook ${hook##*/}"
|
echo "Running pre-install hook ${hook##*/}"
|
||||||
"${hook}"
|
"${hook}"
|
||||||
fi
|
fi
|
||||||
@@ -193,9 +184,9 @@ run_pre_hooks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run_post_hooks() {
|
run_post_hooks() {
|
||||||
local -r target_profile="$1"
|
local -r target_profile=$1
|
||||||
for hook in "${PROFILES_DIR}/${target_profile}"/hooks/post/*; do
|
for hook in "${PROFILES_DIR}/${target_profile}"/hooks/post/*; do
|
||||||
if [[ -f "${hook}" && -x "${hook}" ]]; then
|
if [[ -f ${hook} && -x ${hook} ]]; then
|
||||||
echo "Running post-install hook ${hook##*/}"
|
echo "Running post-install hook ${hook##*/}"
|
||||||
"${hook}"
|
"${hook}"
|
||||||
fi
|
fi
|
||||||
@@ -205,45 +196,37 @@ run_post_hooks() {
|
|||||||
prune_symlinks() {
|
prune_symlinks() {
|
||||||
echo -n "Removing dangling symlinks in home directory... "
|
echo -n "Removing dangling symlinks in home directory... "
|
||||||
|
|
||||||
pushd "${HOME}" >/dev/null
|
pushd "${HOME}" >/dev/null || exit 1
|
||||||
local common_files
|
local common_files
|
||||||
local -r target_profile="$1"
|
local -r target_profile=$1
|
||||||
mapfile -t common_files < <(comm -12 <(find "${HOME}" -type l -printf '%P\n' 2>/dev/null | sort) \
|
mapfile -t common_files < <(comm -12 <(find "${HOME}" -type l -printf '%P\n' 2>/dev/null | sort) \
|
||||||
<(find "${PROFILES_DIR}/${target_profile}" -type f -printf '%P\n' | sort))
|
<(find "${PROFILES_DIR}/${target_profile}" -type f -printf '%P\n' | sort))
|
||||||
local target_file
|
local target_file
|
||||||
for target_file in "${common_files[@]}"; do
|
for target_file in "${common_files[@]}"; do
|
||||||
local -a rm_args=( "--force" )
|
local -a rm_args=(--force)
|
||||||
[[ ${verbose} ]] && rm_args+=( "--verbose" )
|
[[ ${verbose} ]] && rm_args+=(--verbose)
|
||||||
rm "${rm_args[@]}" "${target_file}"
|
rm "${rm_args[@]}" -- "${target_file}"
|
||||||
done
|
done
|
||||||
popd >/dev/null
|
popd >/dev/null || exit 1
|
||||||
|
|
||||||
echo "OK"
|
echo "OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
stow_profile() {
|
stow_profile() {
|
||||||
local -r target_profile="$1"
|
local -r target_profile=$1
|
||||||
local error_log
|
if stow "${STOW_ARGS[@]}" "${target_profile}" 2>&1; then
|
||||||
error_log="$(stow "${STOW_ARGS[@]}" "${target_profile}" 2>&1)"
|
|
||||||
if (( $? == 0 )); then
|
|
||||||
echo "Profile ${target_profile} has been stowed"
|
echo "Profile ${target_profile} has been stowed"
|
||||||
else
|
else
|
||||||
echo "Failed to create symlinks pointing to dotfiles in profile ${target_profile}"
|
echo "Failed to create symlinks pointing to dotfiles in profile ${target_profile}"
|
||||||
echo "Executed command: stow ${STOW_ARGS[*]} ${target_profile}"
|
|
||||||
fi
|
|
||||||
if [[ -n "${error_log}" ]]; then
|
|
||||||
echo "${error_log}" > /tmp/stow-error.log
|
|
||||||
[[ ${verbose} ]] && echo "${error_log}"
|
|
||||||
echo "Error log has been saved into /tmp/stow-error.log"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_parents() {
|
fetch_parents() {
|
||||||
local -r target_profile="$1"
|
local -r target_profile=$1
|
||||||
if [[ -s "${PROFILES_DIR}/${target_profile}/parent" ]]; then
|
if [[ -s ${PROFILES_DIR}/${target_profile}/parent ]]; then
|
||||||
local parent
|
local parent
|
||||||
parent=$(cat "${PROFILES_DIR}/${target_profile}/parent")
|
parent=$(cat "${PROFILES_DIR}/${target_profile}/parent")
|
||||||
if [[ -s "${PROFILES_DIR}/${parent}/parent" ]]; then
|
if [[ -s ${PROFILES_DIR}/${parent}/parent ]]; then
|
||||||
fetch_parents "${parent}"
|
fetch_parents "${parent}"
|
||||||
fi
|
fi
|
||||||
echo "${parent}"
|
echo "${parent}"
|
||||||
@@ -251,7 +234,7 @@ fetch_parents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
build_deptree() {
|
build_deptree() {
|
||||||
local -r target_profile="$1"
|
local -r target_profile=$1
|
||||||
fetch_parents "${target_profile}"
|
fetch_parents "${target_profile}"
|
||||||
echo "${target_profile}"
|
echo "${target_profile}"
|
||||||
}
|
}
|
||||||
@@ -272,7 +255,7 @@ main() {
|
|||||||
require_profiles_dir
|
require_profiles_dir
|
||||||
(( $# == 0 )) && show_general_help && exit 1
|
(( $# == 0 )) && show_general_help && exit 1
|
||||||
validate_args
|
validate_args
|
||||||
[[ -n ${list_profiles} ]] && echo "${PROFILES[@]}" && exit 0
|
[[ ${list_profiles} ]] && echo "${PROFILES[@]}" && exit 0
|
||||||
install_dotfiles
|
install_dotfiles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# emacs specific stuff
|
# emacs specific stuff
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
[[ -n "${EAT_SHELL_INTEGRATION_DIR}" ]] && \
|
[[ ${EAT_SHELL_INTEGRATION_DIR} ]] && . "${EAT_SHELL_INTEGRATION_DIR}/bash"
|
||||||
source "${EAT_SHELL_INTEGRATION_DIR}/bash"
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Set environment variables
|
# Set environment variables
|
||||||
if command -v nvim &> /dev/null; then
|
if command -v nvim >/dev/null 2>&1; then
|
||||||
export EDITOR="nvim"
|
export EDITOR="nvim"
|
||||||
else
|
else
|
||||||
export EDITOR="vim"
|
export EDITOR="vim"
|
||||||
@@ -21,7 +21,7 @@ export GPGKEY="4A45503BBE575E3D4DAF28E27264AFFDC98D52BB"
|
|||||||
|
|
||||||
# gpg-agent
|
# gpg-agent
|
||||||
unset SSH_AGENT_PID
|
unset SSH_AGENT_PID
|
||||||
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
|
if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne "$$" ]]; then
|
||||||
SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null)"
|
SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null)
|
||||||
export SSH_AUTH_SOCK
|
export SSH_AUTH_SOCK
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
# better ls
|
# better ls
|
||||||
if type "eza" > /dev/null; then
|
if command -v eza >/dev/null 2>&1; then
|
||||||
alias ll='eza -bghHlS'
|
alias ll="eza -bghHlS"
|
||||||
else
|
else
|
||||||
alias ll='exa -bghHlS'
|
alias ll="exa -bghHlS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# bat (debian)
|
# bat (debian)
|
||||||
if type "batcat" >/dev/null 2>&1; then
|
if command -v batcat >/dev/null 2>&1; then
|
||||||
alias bat='batcat'
|
alias bat=batcat
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# HSTR configuration - add this to ~/.bashrc
|
# HSTR configuration - add this to ~/.bashrc
|
||||||
@@ -18,7 +18,7 @@ export HISTCONTROL=ignorespace # leading space hides commands from history
|
|||||||
export HISTFILESIZE=10000 # increase history file size (default is 500)
|
export HISTFILESIZE=10000 # increase history file size (default is 500)
|
||||||
export HISTSIZE=${HISTFILESIZE} # increase history size (default is 500)
|
export HISTSIZE=${HISTFILESIZE} # increase history size (default is 500)
|
||||||
# ensure synchronization between bash memory and history file
|
# ensure synchronization between bash memory and history file
|
||||||
export PROMPT_COMMAND=( "history -a; history -n;" "${PROMPT_COMMAND[@]}" )
|
export PROMPT_COMMAND=("history -a; history -n;" "${PROMPT_COMMAND[@]}")
|
||||||
function hstrnotiocsti {
|
function hstrnotiocsti {
|
||||||
{ READLINE_LINE="$( { </dev/tty hstr -- "${READLINE_LINE}"; } 2>&1 1>&3 3>&- )"; } 3>&1;
|
{ READLINE_LINE="$( { </dev/tty hstr -- "${READLINE_LINE}"; } 2>&1 1>&3 3>&- )"; } 3>&1;
|
||||||
READLINE_POINT=${#READLINE_LINE}
|
READLINE_POINT=${#READLINE_LINE}
|
||||||
@@ -27,31 +27,11 @@ function hstrnotiocsti {
|
|||||||
if [[ $- =~ .*i.* ]]; then bind -x '"\C-r": "hstrnotiocsti"'; fi
|
if [[ $- =~ .*i.* ]]; then bind -x '"\C-r": "hstrnotiocsti"'; fi
|
||||||
export HSTR_TIOCSTI=n
|
export HSTR_TIOCSTI=n
|
||||||
|
|
||||||
# lf
|
|
||||||
lfwrapper() {
|
|
||||||
command lf "$@"
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
awk '$1 == "archivemount" { print $2 }' /etc/mtab | while read -r mntdir; do
|
|
||||||
sanitized_input="$(printf "${mntdir}")" # /etc/mtab uses octal representation of spaces (possible other symbols too), printf would convert octal representation, so that it can be used in the umount & rmdir commands.
|
|
||||||
umount "${sanitized_input}"
|
|
||||||
rmdir "${sanitized_input}"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
lfcd() {
|
|
||||||
dir="$(lfwrapper -print-last-dir "$@")"
|
|
||||||
while ! cd "${dir}" 2>/dev/null; do
|
|
||||||
dir="$(dirname -- "${dir}")"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
alias lf=lfcd
|
|
||||||
|
|
||||||
# ranger
|
# ranger
|
||||||
ranger_cd() {
|
ranger_cd() {
|
||||||
temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")"
|
temp_file=$(mktemp -t "ranger_cd.XXXXXXXXXX")
|
||||||
ranger --choosedir="${temp_file}" -- "${@:-${PWD}}"
|
ranger --choosedir="${temp_file}" -- "${@:-${PWD}}"
|
||||||
if chosen_dir="$(cat -- "${temp_file}")" && [ -n "${chosen_dir}" ] && [ "${chosen_dir}" != "${PWD}" ]; then
|
if chosen_dir="$(cat -- "${temp_file}")" && [[ "${chosen_dir}" ]] && [[ "${chosen_dir}" != "${PWD}" ]]; then
|
||||||
cd -- "${chosen_dir}" || exit 1
|
cd -- "${chosen_dir}" || exit 1
|
||||||
fi
|
fi
|
||||||
rm -f -- "${temp_file}"
|
rm -f -- "${temp_file}"
|
||||||
@@ -61,8 +41,8 @@ alias ranger=ranger_cd
|
|||||||
# mc
|
# mc
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
[[ -f "/usr/libexec/mc/mc.sh" ]] && source "/usr/libexec/mc/mc.sh"
|
[[ -f /usr/libexec/mc/mc.sh ]] && . /usr/libexec/mc/mc.sh
|
||||||
[[ -f "/usr/lib/mc/mc.sh" ]] && source "/usr/lib/mc/mc.sh"
|
[[ -f /usr/lib/mc/mc.sh ]] && . /usr/lib/mc/mc.sh
|
||||||
|
|
||||||
# inside tmux, we don't know if Sway got restarted
|
# inside tmux, we don't know if Sway got restarted
|
||||||
if [[ -v TMUX ]]; then
|
if [[ -v TMUX ]]; then
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
# useful commands
|
# useful commands
|
||||||
alias ncmpcpp='ncmpcpp -b ~/.config/ncmpcpp/bindings'
|
alias ncmpcpp="ncmpcpp -b ~/.config/ncmpcpp/bindings"
|
||||||
alias tb='nc termbin.com 9999'
|
alias tb="nc termbin.com 9999"
|
||||||
alias mux='tmuxinator'
|
alias mux="tmuxinator"
|
||||||
alias tm='tmuxinator start misc'
|
alias tm="tmuxinator start misc"
|
||||||
alias tq='tmuxinator start quake'
|
alias tq="tmuxinator start quake"
|
||||||
alias sudo='sudo '
|
alias sudo="sudo "
|
||||||
alias rsync_copy='rsync -aAXUHvh --partial-dir=.rsync-partial --progress'
|
alias rsync_copy="rsync -aAXUHvh --partial-dir=.rsync-partial --progress"
|
||||||
alias rsync_copy_ssh='rsync_copy -e ssh'
|
alias rsync_copy_ssh="rsync_copy -e ssh"
|
||||||
alias rsync_backup='rsync_copy --numeric-ids --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}'
|
alias rsync_backup="rsync_copy --numeric-ids --delete --exclude={'/dev/*','/proc/*','/sys/*','/tmp/*','/run/*','/mnt/*','/media/*','/lost+found'}"
|
||||||
alias rsync_backup_ssh='rsync_backup -e ssh'
|
alias rsync_backup_ssh="rsync_backup -e ssh"
|
||||||
alias rsync_restore='rsync_copy --numeric-ids --delete --exclude="lost+found"'
|
alias rsync_restore="rsync_copy --numeric-ids --delete --exclude='lost+found'"
|
||||||
alias rsync_restore_ssh='rsync_restore -e ssh'
|
alias rsync_restore_ssh="rsync_restore -e ssh"
|
||||||
alias glog='git log --oneline'
|
alias glog="git log --oneline"
|
||||||
alias emerge_world='emerge --ask --verbose --deep --newuse --update @world'
|
alias emerge_world="emerge --ask --verbose --deep --newuse --update @world"
|
||||||
alias sync_repo='rsync_copy_ssh --delete ~/arch_paczuchy/* vps.paraboletancza.org:/srv/http/arch.paraboletancza.org'
|
alias sync_repo="rsync_copy_ssh --delete ~/arch_paczuchy/* vps.paraboletancza.org:/srv/http/arch.paraboletancza.org"
|
||||||
alias aur_sync='aur sync --sign --chroot'
|
alias aur_sync="aur sync --sign --chroot"
|
||||||
alias aur_build='aur build --sign --chroot'
|
alias aur_build="aur build --sign --chroot"
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -o errexit
|
readonly SCRIPT_NAME=${0##*/}
|
||||||
set -o pipefail
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
readonly SCRIPT_NAME="${0##*/}"
|
|
||||||
|
|
||||||
check_deps() {
|
check_deps() {
|
||||||
command -v "curl" >/dev/null 2>&1 || die "curl: command not found"
|
command -v curl >/dev/null 2>&1 || die "curl: command not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
@@ -26,18 +22,18 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
shell_quote() {
|
shell_quote() {
|
||||||
local -r string="$1"
|
local -r string=$1
|
||||||
printf "'%s'" "${string//'/'\\''}"
|
printf "'%s'" "${string//'/'\\''}"
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
local -r message="$1"
|
local -r message=$1
|
||||||
printf "%s: %b\n" "${SCRIPT_NAME}" "${message}" >&2
|
printf "%s: %b\n" "${SCRIPT_NAME}" "${message}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
invalid_option() {
|
invalid_option() {
|
||||||
local -r option="$1"
|
local -r option=$1
|
||||||
die "invalid option $(shell_quote "${option}")\nTry '${SCRIPT_NAME} --help' for usage."
|
die "invalid option $(shell_quote "${option}")\nTry '${SCRIPT_NAME} --help' for usage."
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,11 +44,11 @@ parse_args() {
|
|||||||
-h|--help) usage; exit 0 ;;
|
-h|--help) usage; exit 0 ;;
|
||||||
--family)
|
--family)
|
||||||
( (( $# < 2 )) || [[ -z "$2" ]] ) && die "--family requires an argument (auto, 4 or 6)"
|
( (( $# < 2 )) || [[ -z "$2" ]] ) && die "--family requires an argument (auto, 4 or 6)"
|
||||||
family="$2"
|
family=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--family=*)
|
--family=*)
|
||||||
family="${1#*=}"
|
family=${1#*=}
|
||||||
[[ -z "${family}" ]] && die "--family requires an argument (auto, 4 or 6)"
|
[[ -z "${family}" ]] && die "--family requires an argument (auto, 4 or 6)"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
@@ -63,7 +59,7 @@ parse_args() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate_args() {
|
validate_args() {
|
||||||
case "${family}" in
|
case ${family} in
|
||||||
auto|4|6) ;;
|
auto|4|6) ;;
|
||||||
*) die "invalid value for family: '${family}' (expected auto, 4 or 6)"
|
*) die "invalid value for family: '${family}' (expected auto, 4 or 6)"
|
||||||
esac
|
esac
|
||||||
@@ -71,9 +67,9 @@ validate_args() {
|
|||||||
|
|
||||||
show_ip() {
|
show_ip() {
|
||||||
local -a curl_args=()
|
local -a curl_args=()
|
||||||
[[ ${family} == "4" ]] && curl_args=( "-4" )
|
[[ ${family} == "4" ]] && curl_args=("-4")
|
||||||
[[ ${family} == "6" ]] && curl_args=( "-6" )
|
[[ ${family} == "6" ]] && curl_args=("-6")
|
||||||
curl "${curl_args[@]}" "zx2c4.com/ip"
|
curl "${curl_args[@]}" zx2c4.com/ip
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
## user experience related stuff
|
## user experience related stuff
|
||||||
|
|
||||||
|
# preserve some environment variables
|
||||||
|
set-option -g update-environment "REAL_TERM"
|
||||||
|
|
||||||
# fix delay between switching modes in vim
|
# fix delay between switching modes in vim
|
||||||
set -sg escape-time 20
|
set -sg escape-time 20
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# Set PATH environment variable
|
# Set PATH environment variable
|
||||||
typeset -U path PATH
|
typeset -U path PATH
|
||||||
path=("${HOME}/.local/bin" "/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/sbin" "${path[@]}")
|
path=("${HOME}/.local/bin" /usr/local/sbin /usr/local/bin /usr/sbin /sbin "${path[@]}")
|
||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
# Configure shell history behavior
|
# Configure shell history behavior
|
||||||
HISTFILE="${HOME}/.zsh_history"
|
HISTFILE=${HOME}/.zsh_history
|
||||||
HISTSIZE=10000
|
HISTSIZE=10000
|
||||||
SAVEHIST=10000
|
SAVEHIST=10000
|
||||||
setopt appendhistory
|
setopt appendhistory
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
|
|
||||||
# Initialization code that may require console input (password prompts, [y/n]
|
|
||||||
# confirmations, etc.) must go above this block; everything else may go below.
|
|
||||||
if [[ -r "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
|
|
||||||
source "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# plugins
|
|
||||||
source "${HOME}/.zsh/plugins/powerlevel10k/powerlevel10k.zsh-theme"
|
|
||||||
source "${HOME}/.zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
|
|
||||||
|
|
||||||
# To customize prompt, run `p10k configure` or edit ~/.zsh/prompt/p10k.zsh.
|
|
||||||
[[ -f "${HOME}/.zsh/prompt/p10k.zsh" ]] && source "${HOME}/.zsh/prompt/p10k.zsh"
|
|
||||||
@@ -14,19 +14,23 @@ bindkey '^U' backward-kill-line
|
|||||||
# Change cursor shape for different vi modes
|
# Change cursor shape for different vi modes
|
||||||
zle-keymap-select() {
|
zle-keymap-select() {
|
||||||
if [[ ${KEYMAP} == vicmd ]] ||
|
if [[ ${KEYMAP} == vicmd ]] ||
|
||||||
[[ $1 = "block" ]]; then
|
[[ $1 == block ]]; then
|
||||||
echo -ne '\e[4 q'
|
echo -ne '\e[4 q'
|
||||||
|
psvar[1]="(cmd) "
|
||||||
elif [[ ${KEYMAP} == main ]] ||
|
elif [[ ${KEYMAP} == main ]] ||
|
||||||
[[ ${KEYMAP} == viins ]] ||
|
[[ ${KEYMAP} == viins ]] ||
|
||||||
[[ ${KEYMAP} == "" ]] ||
|
[[ -z ${KEYMAP} ]] ||
|
||||||
[[ $1 == "beam" ]]; then
|
[[ $1 == beam ]]; then
|
||||||
echo -ne '\e[6 q'
|
echo -ne '\e[6 q'
|
||||||
|
psvar[1]="(ins) "
|
||||||
fi
|
fi
|
||||||
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
zle -N zle-keymap-select
|
zle -N zle-keymap-select
|
||||||
zle-line-init() {
|
zle-line-init() {
|
||||||
zle -K viins # Initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
|
zle -K viins # Initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
|
||||||
echo -ne '\e[6 q'
|
echo -ne '\e[6 q'
|
||||||
|
psvar[1]="(ins) "
|
||||||
}
|
}
|
||||||
zle -N zle-line-init
|
zle -N zle-line-init
|
||||||
echo -ne '\e[6 q' # Use beam shape cursor on startup
|
echo -ne '\e[6 q' # Use beam shape cursor on startup
|
||||||
19
profiles/base/.zsh/conf.d/02-prompt.zsh
Normal file
19
profiles/base/.zsh/conf.d/02-prompt.zsh
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
if [[ -z ${TMUX} ]]; then
|
||||||
|
export REAL_TERM=${TERM}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${REAL_TERM} != "linux" ]]; then
|
||||||
|
# To customize prompt, run `p10k configure` or edit ~/.zsh/prompt/p10k.zsh.
|
||||||
|
. "${HOME}/.zsh/plugins/powerlevel10k/powerlevel10k.zsh-theme"
|
||||||
|
|
||||||
|
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
|
||||||
|
# Initialization code that may require console input (password prompts, [y/n]
|
||||||
|
# confirmations, etc.) must go above this block; everything else may go below.
|
||||||
|
if [[ -r "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
|
||||||
|
. "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -f ${HOME}/.zsh/prompt/p10k.zsh ]] && . "${HOME}/.zsh/prompt/p10k.zsh"
|
||||||
|
else
|
||||||
|
. "${HOME}/.zsh/prompt/fallback.zsh"
|
||||||
|
fi
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
## Plugins configuration
|
## Plugins configuration
|
||||||
|
|
||||||
|
# Automatic suggestions
|
||||||
|
. "${HOME}/.zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
|
||||||
|
|
||||||
# Completions
|
# Completions
|
||||||
fpath=("${HOME}/.zsh/plugins/zsh-completions/src" "${fpath[@]}")
|
fpath=("${HOME}/.zsh/plugins/zsh-completions/src" "${fpath[@]}")
|
||||||
autoload -U compinit promptinit
|
autoload -U compinit promptinit
|
||||||
compinit
|
compinit
|
||||||
promptinit
|
promptinit
|
||||||
[[ -f "/etc/gentoo-release" ]] && prompt gentoo
|
[[ -f /etc/gentoo-release ]] && prompt gentoo
|
||||||
|
|
||||||
# Enable cache for completions
|
# Enable cache for completions
|
||||||
zstyle ":completion::complete:*" use-cache 1
|
zstyle ":completion::complete:*" use-cache 1
|
||||||
|
|
||||||
# Syntax highlighting in zsh prompt
|
# Syntax highlighting in zsh prompt
|
||||||
source "${HOME}/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
. "${HOME}/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
# emacs specific stuff
|
# emacs specific stuff
|
||||||
[ -n "${EAT_SHELL_INTEGRATION_DIR}" ] && \
|
[[ ${EAT_SHELL_INTEGRATION_DIR} ]] && . "${EAT_SHELL_INTEGRATION_DIR}/zsh"
|
||||||
source "${EAT_SHELL_INTEGRATION_DIR}/zsh"
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Set environment variables
|
# Set environment variables
|
||||||
if command -v nvim &> /dev/null; then
|
if command -v nvim >/dev/null 2>&1; then
|
||||||
export EDITOR="nvim"
|
export EDITOR="nvim"
|
||||||
else
|
else
|
||||||
export EDITOR="vim"
|
export EDITOR="vim"
|
||||||
@@ -21,6 +21,6 @@ export GPGKEY="4A45503BBE575E3D4DAF28E27264AFFDC98D52BB"
|
|||||||
|
|
||||||
# gpg-agent
|
# gpg-agent
|
||||||
unset SSH_AGENT_PID
|
unset SSH_AGENT_PID
|
||||||
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
|
if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then
|
||||||
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null)"
|
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null)
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ pty() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ptyless() {
|
ptyless() {
|
||||||
pty $@ | less
|
pty "$@" | less
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
# HSTR configuration - add this to ~/.zshrc
|
# HSTR configuration - add this to ~/.zshrc
|
||||||
if type "hstr" >/dev/null; then
|
if command -v hstr >/dev/null 2>&1; then
|
||||||
alias hh=hstr # hh to be alias for hstr
|
alias hh=hstr # hh to be alias for hstr
|
||||||
setopt histignorespace # skip cmds w/ leading space from history
|
setopt histignorespace # skip cmds w/ leading space from history
|
||||||
export HSTR_CONFIG=hicolor # get more colors
|
export HSTR_CONFIG=hicolor # get more colors
|
||||||
hstr_no_tiocsti() {
|
hstr_no_tiocsti() {
|
||||||
zle -I
|
zle -I
|
||||||
{ HSTR_OUT="$( { </dev/tty hstr ${BUFFER}; } 2>&1 1>&3 3>&- )"; } 3>&1;
|
{ HSTR_OUT="$( { </dev/tty hstr ${BUFFER}; } 2>&1 1>&3 3>&- )"; } 3>&1;
|
||||||
BUFFER="${HSTR_OUT}"
|
BUFFER=${HSTR_OUT}
|
||||||
CURSOR=${#BUFFER}
|
CURSOR=${#BUFFER}
|
||||||
zle redisplay
|
zle redisplay
|
||||||
}
|
}
|
||||||
@@ -18,42 +18,22 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# better ls
|
# better ls
|
||||||
if command -v "eza" >/dev/null 2>&1; then
|
if command -v eza >/dev/null 2>&1; then
|
||||||
alias ll="eza -bghHlS"
|
alias ll="eza -bghHlS"
|
||||||
else
|
else
|
||||||
alias ll="exa -bghHlS"
|
alias ll="exa -bghHlS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# bat (debian)
|
# bat (debian)
|
||||||
if command -v "batcat" >/dev/null 2>&1; then
|
if command -v batcat >/dev/null 2>&1; then
|
||||||
alias bat="batcat"
|
alias bat=batcat
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# lf
|
|
||||||
lfwrapper() {
|
|
||||||
command lf "$@"
|
|
||||||
|
|
||||||
# cleanup
|
|
||||||
awk '$1 == "archivemount" { print $2 }' /etc/mtab | while read -r mntdir; do
|
|
||||||
sanitized_input="$(printf "${mntdir}")" # /etc/mtab uses octal representation of spaces (possible other symbols too), printf would convert octal representation, so that it can be used in the umount & rmdir commands.
|
|
||||||
umount "${sanitized_input}"
|
|
||||||
rmdir "${sanitized_input}"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
lfcd() {
|
|
||||||
dir="$(lfwrapper -print-last-dir "$@")"
|
|
||||||
while ! cd "${dir}" 2>/dev/null; do
|
|
||||||
dir="$(dirname -- "${dir}")"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
alias lf=lfcd
|
|
||||||
|
|
||||||
# ranger
|
# ranger
|
||||||
ranger_cd() {
|
ranger_cd() {
|
||||||
temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")"
|
temp_file=$(mktemp -t "ranger_cd.XXXXXXXXXX")
|
||||||
ranger --choosedir="${temp_file}" -- "${@:-${PWD}}"
|
ranger --choosedir="${temp_file}" -- "${@:-${PWD}}"
|
||||||
if chosen_dir="$(cat -- "${temp_file}")" && [ -n "${chosen_dir}" ] && [ "${chosen_dir}" != "${PWD}" ]; then
|
if chosen_dir=$(cat -- "${temp_file}") && [ -n ${chosen_dir} ] && [ ${chosen_dir} != "${PWD}" ]; then
|
||||||
cd -- "${chosen_dir}"
|
cd -- "${chosen_dir}"
|
||||||
fi
|
fi
|
||||||
rm -f -- "${temp_file}"
|
rm -f -- "${temp_file}"
|
||||||
@@ -61,31 +41,31 @@ ranger_cd() {
|
|||||||
alias ranger=ranger_cd
|
alias ranger=ranger_cd
|
||||||
|
|
||||||
# mc
|
# mc
|
||||||
if [ -f "/usr/libexec/mc/mc.sh" ]; then
|
if [[ -f /usr/libexec/mc/mc.sh ]]; then
|
||||||
source "/usr/libexec/mc/mc.sh"
|
. /usr/libexec/mc/mc.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# nix package manager
|
# nix package manager
|
||||||
if [ -e "${HOME}/.nix-profile/etc/profile.d/nix.sh" ]; then
|
if [[ -e "${HOME}/.nix-profile/etc/profile.d/nix.sh" ]]; then
|
||||||
source "${HOME}/.nix-profile/etc/profile.d/nix.sh"
|
. "${HOME}/.nix-profile/etc/profile.d/nix.sh"
|
||||||
fi # added by Nix installer
|
fi
|
||||||
|
|
||||||
# nix shell
|
# nix shell
|
||||||
if command -v nix-your-shell >/dev/null 2>&1; then
|
if command -v nix-your-shell >/dev/null 2>&1; then
|
||||||
nix-your-shell zsh | source /dev/stdin
|
nix-your-shell zsh | . /dev/stdin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# node.js
|
# node.js
|
||||||
export NVM_DIR="${HOME}/.nvm"
|
export NVM_DIR="${HOME}/.nvm"
|
||||||
[ -s "${NVM_DIR}/nvm.sh" ] && source "${NVM_DIR}/nvm.sh" # This loads nvm
|
[[ -s ${NVM_DIR}/nvm.sh ]] && . "${NVM_DIR}/nvm.sh" # This loads nvm
|
||||||
[ -s "${NVM_DIR}/bash_completion" ] && source "${NVM_DIR}/bash_completion" # This loads nvm bash_completion
|
[[ -s ${NVM_DIR}/bash_completion ]] && . "${NVM_DIR}/bash_completion" # This loads nvm bash_completion
|
||||||
|
|
||||||
# rvm
|
# rvm
|
||||||
[ -s "${HOME}/.rvm/scripts/rvm" ] && source "${HOME}/.rvm/scripts/rvm"
|
[[ -s ${HOME}/.rvm/scripts/rvm ]] && . "${HOME}/.rvm/scripts/rvm"
|
||||||
|
|
||||||
# pyenv
|
# pyenv
|
||||||
export PYENV_ROOT="${HOME}/.pyenv"
|
export PYENV_ROOT=${HOME}/.pyenv
|
||||||
if [[ -d "${PYENV_ROOT}/bin" ]]; then
|
if [[ -d ${PYENV_ROOT}/bin ]]; then
|
||||||
path=("${PYENV_ROOT}/bin" "${path[@]}")
|
path=("${PYENV_ROOT}/bin" "${path[@]}")
|
||||||
export PATH
|
export PATH
|
||||||
eval "$(pyenv init - zsh)"
|
eval "$(pyenv init - zsh)"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
alias ncmpcpp="ncmpcpp -b ${HOME}/.config/ncmpcpp/bindings"
|
alias ncmpcpp="ncmpcpp -b ~/.config/ncmpcpp/bindings"
|
||||||
alias tb="nc termbin.com 9999"
|
alias tb="nc termbin.com 9999"
|
||||||
alias mux="tmuxinator"
|
alias mux="tmuxinator"
|
||||||
alias tm="tmuxinator start misc"
|
alias tm="tmuxinator start misc"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
take() {
|
take() {
|
||||||
local -r directory="$1"
|
local -r directory=$1
|
||||||
mkdir -p "${directory}"
|
mkdir -p "${directory}"
|
||||||
cd "${directory}"
|
cd "${directory}"
|
||||||
}
|
}
|
||||||
|
|||||||
8
profiles/base/.zsh/prompt/fallback.zsh
Normal file
8
profiles/base/.zsh/prompt/fallback.zsh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
if (( EUID == 0 )); then
|
||||||
|
# If root, omit the username and print the hostname in red.
|
||||||
|
PS1='%1v%B%F\h %(?..%? )%F{blue}%~ # %f%b'
|
||||||
|
else
|
||||||
|
# Otherwise, print the username and hostname in green.
|
||||||
|
PS1='%1v%B%F{green}%n@%m%F{blue} %(?..%F{red}%? %F{blue})%~ $ %f%b'
|
||||||
|
fi
|
||||||
|
RPROMPT=$(date '+%H:%m:%S')
|
||||||
Reference in New Issue
Block a user