custom_themes/
cache/
repos/
+debug
--- /dev/null
+Alexander Barton <alex@barton.de> <abarton@thomas-daily.de>
+Alexander Barton <alex@barton.de> <alexander.barton@tomas-daily.de>
The MIT License
===============
-- Copyright (c) 2015-2019 Alexander Barton <alex@barton.de>
+- Copyright (c) 2015-2023 Alexander Barton <alex@barton.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
-AX-ZSH: Alex' Modular ZSH Configuration
-=======================================
+# AX-ZSH: Alex' Modular ZSH Configuration
-AX-ZSH is a modular configuration system for the Z shell (ZSH).
+[AX-ZSH] is a modular configuration system for the Z shell ([ZSH]).
It provides sane defaults and is extendable by plugins.
-Installation
-------------
+AX-ZSH integrates well with [Powerlevel10k] and other extensions, even plugins
+of [OhMyZsh], see [below](#integration-with-other-projects).
-To install AX-ZSH, either download a source archive or use Git to clone it.
-Afterwards use the `install.sh` script inside of the source directory to set
-up the `~/.axzsh` directory.
+The homepage of [AX-ZSH] can be found at [GitHub]:
+<https://github.com/alexbarton/ax-zsh>.
-When using Git it is best to directly clone the AX-ZSH repository into the
-`~/.axzsh` directory and call `install.sh` from this location.
+## Installation
-Clone repository from _GitHub_ (<https://github.com/alexbarton/ax-zsh>):
+Prerequisites:
- git clone https://github.com/alexbarton/ax-zsh.git ~/.axzsh
+* [ZSH] – obviously ;-)
+* [Git] (optional but recommended!)
-Then run the installer script:
+Installing AX-ZSH is a two-step process:
- ~/.axzsh/install.sh
+1. Clone or copy the source files into the `~/.axzsh` directory,
+2. Run the `~/.axzsh/install.sh` script.
The `install.sh` script creates symbolic links for `~/.zprofile`, `~/.zshrc`,
`~/.zlogin`, and `~/.zlogout` (don't worry, already existing files are backed
up).
-Now close and restart all your running ZSH session to activate AX-ZSH.
+*Note:* The installation is per-user and only changes/installs files into the
+home directory of the current user (`~`). AX-ZSH is not meant to be installed
+globally for all users on a system at once, and you don't need to become "root"
+or any other user with elevated privileges!
-To update AX-ZSH run `axzshctl upgrade`.
+### Installation using Git
-AX-ZSH & Local ZSH Configuration
---------------------------------
+When using [Git], the preferred method, it is best to directly clone the AX-ZSH
+repository into the `~/.axzsh` directory and call `install.sh` from this
+location:
-Plugins are loaded when they are linked into the `$AXZSH/active_plugins/`
-directory; see the _Customization_ section below for how to activate them.
+```sh
+git clone https://github.com/alexbarton/ax-zsh.git ~/.axzsh
+~/.axzsh/install.sh
+```
-Don't modify `~/.zprofile`, `~/.zshrc`, `~/.zlogin`, or `~/.zlogout`! These
-are links to "AX-ZSH"-private files that can become overwritten when updating.
+### Installation without Git
-You can use the following files for local ZSH configuration:
+*Note:* If you do not install AX-ZSH with [Git], you will not be able to upgrade
+itself afterwards with the integrated `axzsh upgrade` command! Therefore this
+method is *not recommended* for normal use!
-1. AX-ZSH doesn't use `~/.zshenv` in any way. So you can use this file for your
- own purposes (for example, to set up some environment variables that AX-ZSH
- relies on).
+```sh
+curl -Lo ax-zsh-master.zip https://github.com/alexbarton/ax-zsh/archive/refs/heads/master.zip
+unzip ax-zsh-master.zip
+mv ax-zsh-master ~/.axzsh
+~/.axzsh/install.sh
+```
-2. AX-ZSH reads the optional files `~/.zprofile.local`, `~/.zshrc.local`,
- `~/.zlogin.local`, and `~/.zlogout.local` after its own core initialization
- files when present.
+### Post-Installation Tasks
+
+After installing AX-ZSH, using Git or via an archive file, you should close all
+running ZSH sessions and restart them to activate AX-ZSH. And maybe you want to
+change your default shell to ZSH if you haven't already?
+
+For example like this:
+
+```sh
+# Set new default shell
+chsh -s $(command -v zsh)
+
+# Replace running shell with a ZSH login shell
+exec $(command -v zsh) -l
+```
+
+## Upgrade
+
+When you used Git to install AX-ZSH (and/or plugins), you can use the `axzshctl`
+command to upgrade AX-ZSH itself and external plugins like this:
+
+```sh
+axzshctl upgrade
+```
+
+## Usage
+
+AX-ZSH comes with a hopefully sane default configuration and can be extended
+using plugins. Different types of plugins are supported:
+
+* Plugins shipped with AX-ZSH.
+* Themes shipped with AX-ZSH.
+* 3rd-party plugins:
+ * installed manually into `$AXZSH/custom_plugins`
+ * stand-alone plugins stored on GitHub
+ * plugins of OhMyZsh from its GitHub repository
+* 3rd-party themes:
+ * installed manually into `$AXZSH/custom_themes`
+ * some stand-alone themes stored on GitHub
+
+### Check whether all locally available "useful" plug-ins are activated
+
+Most plugins can be enabled even when the commands they work with aren't
+available and won't do any harm. But to keep ZSH startup times low, you should
+only enable plugins that are useable on your local system and which you actually
+plan to use.
+
+You can use the following command to let AX-ZSH scan the status of all locally
+available plugins:
+
+```sh
+axzshctl check-plugins
+```
+
+It will summarize the status of all enabled plugins, and suggest to enable
+plugins which seem to make sense on the system and to disable enabled plugins
+that seem not to be supported (for example because of missing dependencies).
+
+### List enabled plugins
+
+Run the following command to list all currently enabled plugins:
+
+```sh
+axzshctl list-enabled
+```
+
+### Enable plugins
+
+AX-ZSH comes with a sane "core ZSH configuration", but it can show its true
+strengths when enabling additional plugins for additional tools and commands
+that are available on your system and you want to use.
+
+Different types of plugins are supported (see the introduction to the section
+"*usage*" above) which are differentiated by their identifier:
+
+* `<name>`: locally available plugin, either bundled with AX-ZSH itself, or
+ installed manually (see below).
+* `<repository>/<name>`: stand-alone [GitHub] repository.
+* `@ohmyzsh/<name>`: [OhMyZsh] plugin from the OhMyZsh GitHub
+ repository (see <https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins>).
+
+You can enable one or more plugins like this:
+
+```sh
+axzshctl enable-plugin <identifier> [<identifier> […]]
+```
+
+*Hint:* *Tab-completion* works for sub-commands and already locally available
+plugin names!
+
+Some examples:
+
+```sh
+# Enable some plugins bundled with AX-ZSH:
+axzshctl enable-plugin editor_select git ssh_autoadd
-Customization
--------------
+# Enable the Powerlevel10k "theme plugin" from GitHub, see
+# <https://github.com/romkatv/powerlevel10k>:
+axzshctl enable-plugin romkatv/powerlevel10k
-Use the `axzshctl` tool to enable, disable, and reset plugins. AXZSH
-initializes an alias which points to the actual location in `~/.axzsh/bin/`.
+# Enable the "fast-syntax-highlighting" plugin from GitHub, see
+# <https://github.com/zdharma-continuum/fast-syntax-highlighting>:
+axzshctl enable-plugin zdharma-continuum/fast-syntax-highlighting
-See `axzshctl --help` for details.
+# Enable the Git and tmux plugins of OhMyZsh:
+axzshctl enable-plugin @ohmyzsh/git @ohmyzsh/tmux
+```
+
+#### Custom local plugins
You can link custom plugins stored in arbitrary directories using `axzshctl`
by specifying the complete path name. Or you can place additional plugins into
-the `~/.axzsh/custom_plugins` folder which is searched by the `axzshctl` tool
+the `$AXZSH/custom_plugins` folder which is searched by the `axzshctl` tool
by default.
In addition you can set the `AXZSH_PLUGIN_D` variable (and `ZSH_CUSTOM` like
-"OhMyZsh") to specify additional plugin search directories.
+[OhMyZsh]) to specify additional plugin search directories.
+
+### Disable plugins
+
+Run the following command to disable a currently enabled plugin:
+
+```sh
+axzshctl disable-plugin <identifier> [<identifier> […]]
+```
+
+*Hint:* *Tab-completion* works for sub-commands and plugin names!
+
+### Update plugin cache
+
+AX-ZSH uses a "plugin cache" to speedup ZSH start times. This cache is
+automatically updated when using the `axzshctl` sub-commands, for example when
+enabling or disabling plugins, or when upgrading the AX-ZSH installation and
+all plugins.
+
+But you *have to* update the cache when manually installing plugins or during
+development of a own local plugin after updating its code!
+
+Run the following command to update the AX-ZSH cache:
+
+```sh
+axzshctl update-caches
+```
+
+### Other `axzshctl` sub-commands
+
+Please run `axzshctl --help` to get a full list of a available sub-commands:
+
+```sh
+axzshctl --help
+```
+
+## Integration with other projects
+
+### Powerlevel10k
+
+AX-ZSH supports [Powerlevel10k] out of the box, you just have to install it as a
+plugin:
+
+```sh
+axzshctl enable-plugin romkatv/powerlevel10k
+```
+
+*Hint:* Once the Powerlevel10k plugin theme is installed, you can use the
+regular `axzshctl set-theme` command to enable it, like for any other installed
+theme: `axzshctl set-theme powerlevel10k`.
-Environment Variables
----------------------
+## AX-ZSH & local ZSH configuration
+
+Don't modify `~/.zprofile`, `~/.zshrc`, `~/.zlogin`, or `~/.zlogout`! These
+are links to "AX-ZSH"-private files that can become overwritten when updating.
+
+You can use the following files for local ZSH configuration:
+
+1. AX-ZSH doesn't use `~/.zshenv` in any way. So you can use this file for your
+ own purposes (for example, to set up some environment variables that AX-ZSH
+ relies on).
+
+2. AX-ZSH reads the optional files `~/.zprofile.local`, `~/.zshrc.local`,
+ `~/.zlogin.local`, and `~/.zlogout.local` after its own core initialization
+ files when present.
+
+## Environment variables
Expected to be already set:
Validated and/or set up by core plugins:
-* `AXZSH`
+* `AXZSH` – AX-ZSH installation directory
* `HOST`
* `HOSTNAME` (same as HOST, deprecated)
* `LOCAL_HOME`
* `PS1`
* `SHORT_HOST`
* `TERM`
-* `XDG_RUNTIME_DIR`
+* `TMPDIR` (set and always ends with a "/")
* `XDG_CACHE_HOME`
+* `XDG_RUNTIME_DIR`
* `ZSH_CACHE_DIR`
+
+___
+[AX-ZSH]: <https://github.com/alexbarton/ax-zsh> "AX-ZSH Homepage"
+[Git]: <https://git-scm.com/> "Git Homepage"
+[GitHub]: <https://github.com/> "GitHub Homepage"
+[OhMyZsh]: <https://ohmyz.sh/> "OhMyZsh Homepage"
+[Powerlevel10k]: <https://github.com/romkatv/powerlevel10k> "Powerlevel10k Homepage"
+[ZSH]: <https://www.zsh.org/> "ZSH Homepage"
+
+[AX-ZSH] Copyright (c) 2015-2022 Alexander Barton <alex@barton.de>
# AX-ZSH: Alex' Modular ZSH Configuration
-# Copyright (c) 2015-2020 Alexander Barton <alex@barton.de>
+# Copyright (c) 2015-2024 Alexander Barton <alex@barton.de>
script_name="${${(%):-%N}:t}"
script_type="$script_name[2,-1]"
# - $1: Script name
# - $2: Stage name (ax-io, zprofile, zshrc, zlogin, zlogout)
function axzsh_handle_stage {
- name="$1"
- type="$2"
+ local name="$1"
+ local type="$2"
[[ -n "$AXZSH_DEBUG" ]] && echo "» $name ($type):"
+ # Look for some 3rd-party integrations ...
+
+ # --- Powerlevel10k ---
+ # Read in Powerlevel10k configuration file, if not already read:
+ [[ -z "$POWERLEVEL9K_CONFIG_FILE" && -r ~/.p10k.zsh ]] && source ~/.p10k.zsh
+ # Enable instant prompt. Should stay close to the top of ~/.zshrc.
+ # Initialization code that may require console input (password prompts,
+ # [y/n] confirmations, etc.) must be executed before this, so all ax-zsh
+ # plugins should do output in their "ax-io" stage only!
+ # Read the initialization script in the "zprofile" stage for login
+ # shells, and in the "zshrc" stage for non-login sub-shells (which have
+ # the profile already read in and therefore will skip the "ax-io" and
+ # "zprofile" stages and not catch up).
+ if [[ \
+ ( "$type" == "zprofile" ) || \
+ ( ! -o login && "$type" == "zshrc" && -n "$AXZSH_ZPROFILE_READ" ) \
+ ]]; then
+ p10k_instant_prompt="${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
+ if [[ -r "$p10k_instant_prompt" ]]; then
+ [[ -n "$AXZSH_DEBUG" ]] && echo " Reading \"$p10k_instant_prompt\" ..."
+ source "$p10k_instant_prompt"
+ fi
+ unset p10k_instant_prompt
+ fi
+
# Initialize cache
- mkdir -p "$AXZSH/cache"
- cache_file="$AXZSH/cache/$type.cache"
+ [[ -d "$AXZSH/cache" ]] || mkdir -p "$AXZSH/cache"
+ local cache_file="$AXZSH/cache/$type.cache"
- cat_cmd=${commands[cat]:-cat}
+ local cat_cmd=${commands[cat]:-cat}
if [[ -r "$cache_file" ]]; then
# Cache file exists, use it!
[[ -n "$AXZSH_DEBUG" ]] \
&& echo " - Reading cache file \"$cache_file\" ..."
source "$cache_file"
- unfunction ax_plugin_init
+ (( $+functions[axzsh_plugin_init] )) && unfunction axzsh_plugin_init
else
# No cache file available.
+ local new_cache_file="$cache_file.NEW"
+
# Setup list of plugins to load:
+ local plugin_list
typeset -U plugin_list
plugin_list=(
- "$AXZSH/core/"[0-5]*
+ "$AXZSH/core/"[0-4]*
"$AXZSH/active_plugins/"*(N)
- "$AXZSH/core/"[6-9]*
+ "$AXZSH/core/"[5-9]*
)
# Create new cache file:
- if [[ -n "$cache_file" ]]; then
- [[ -n "$AXZSH_DEBUG" ]] \
- && echo " (Writing new cache file to \"$cache_file\" ...)"
- printf "# %s\n\n" "$(LC_ALL=C date)" >"$cache_file"
+ [[ -n "$AXZSH_DEBUG" ]] \
+ && echo " (Writing new cache file to \"$new_cache_file\" ...)"
+ if ! printf "# %s\n\n" "$(LC_ALL=C date)" >"$new_cache_file"; then
+ unset new_cache_file
+ else
+ # New cache file successfully created ...
+ if [[ "$type" = "ax-io" ]]; then
+ # AX-IO Stage:
+ # Write an initial PATH variable to the cache
+ # file, which becomes overwritten by the path
+ # plugin at the "zprofile" stage later on, but
+ # this way "ax-io" stage plugins have a somewhat
+ # saner PATH to begin with ...
+ printf 'export PATH="%s"\n\n' "$PATH" >>"$new_cache_file"
+ fi
fi
# Read in all the plugins for the current "type":
if [[ "$plugin:t" == "99_cleanup" && "$type" = "zshrc" ]]; then
if [[ -r "$AXZSH_THEME" ]]; then
source "$AXZSH_THEME"
- if [[ -n "$cache_file" ]]; then
+ if [[ -n "$new_cache_file" ]]; then
# Source the theme in the new cache file:
- echo "# BEGIN Theme" >>"$cache_file"
- echo 'source "$AXZSH_THEME"' >>"$cache_file"
- echo "# END Theme" >>"$cache_file"
+ echo "# BEGIN Theme" >>"$new_cache_file"
+ echo 'source "$AXZSH_THEME"' >>"$new_cache_file"
+ echo "# END Theme" >>"$new_cache_file"
fi
fi
fi
- axzsh_load_plugin "$plugin" "$type" "$cache_file"
+ axzsh_load_plugin "$plugin" "$type" "$new_cache_file"
done
+
+ if [[ -n "$cache_file" && -n "$new_cache_file" && -r "$new_cache_file" ]]; then
+ # Move newly created cache file in place:
+ mv "$new_cache_file" "$cache_file"
+ fi
fi
}
# Oh My ZSH plugin with "zsh-" prefix stripped
type="plugin.zsh"
fname="$dname/${plugin_short##zsh-}.plugin.zsh"
+ elif [[ -r "$dname/${plugin%.plugin.zsh}.plugin.zsh" ]]; then
+ # Oh My ZSH plugin with ".plugin.zsh" suffix in its name
+ type="plugin.zsh"
+ fname="$dname/${plugin}"
elif [[ -r "$dname/init.zsh" ]]; then
# Prezto module
type="init.zsh"
if [[ -n "$cache_file" ]]; then
# Add plugin data to cache
- printf "# BEGIN: %s\nax_plugin_init()\n{\n" "$fname" >>"$cache_file"
+ printf "# BEGIN: %s\naxzsh_plugin_init()\n{\n" "$fname" >>"$cache_file"
case "$fname" in
*"/repos/"*)
echo "[[ -n \"\$AXZSH_DEBUG\" ]] && echo ' - $plugin ($type): \"$fname\" ...'" >>$cache_file
echo "[[ -n \"\$AXZSH_DEBUG\" ]] && echo ' - $plugin ($type, cached) ...'" >>$cache_file
"$cat_cmd" "$fname" >>"$cache_file"
esac
- printf "}\nax_plugin_init\n# END: %s\n\n" "$fname" >>"$cache_file"
+ printf "}\naxzsh_plugin_init\n# END: %s\n\n" "$fname" >>"$cache_file"
fi
fi
[[ -n "$SHELL" ]] || export SHELL=$(command -v zsh)
# Make sure that "AXZSH" variable is set and exported
-if [[ -z "$AXZSH" ]]; then
- export AXZSH="$HOME/.axzsh"
- if [[ -f "$HOME/.axzsh.debug" ]]; then
- export AXZSH_DEBUG=1
- echo "AXZSH=$AXZSH"
- echo "AXZSH_DEBUG=$AXZSH_DEBUG"
- echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
- fi
+[[ -n "$AXZSH" ]] || export AXZSH="${ZDOTDIR:-$HOME}/.axzsh"
+
+# Check for "debug mode" ...
+if [[ -f "$AXZSH/debug" || -f "$HOME/.axzsh.debug" ]]; then
+ export AXZSH_DEBUG=1
+ export POWERLEVEL9K_INSTANT_PROMPT=quiet
+ echo "AXZSH=$AXZSH"
+ echo "AXZSH_DEBUG=$AXZSH_DEBUG"
+ echo "AXZSH_PLUGIN_D=$AXZSH_PLUGIN_D"
+ echo "AXZSH_ZLOGIN_READ=$AXZSH_ZLOGIN_READ"
+ echo "AXZSH_ZPROFILE_READ=$AXZSH_ZPROFILE_READ"
fi
if [[ "$script_type" = "zprofile" ]]; then
axzsh_handle_stage "$script_name" "ax-io"
fi
-# Look for some 3rd-party integrations ...
-
-# --- Powerlevel10k ---
-# Read in Powerlevel10k configuration file, if not already read:
-[[ -z "$POWERLEVEL9K_CONFIG_FILE" && -r ~/.p10k.zsh ]] && source ~/.p10k.zsh
-# Enable instant prompt. Should stay close to the top of ~/.zshrc.
-# Initialization code that may require console input (password prompts,
-# [y/n] confirmations, etc.) must be executed before this, so all ax-zsh
-# plugings should do output in their "zprofile" stage!
-if [[ "$script_type" == "zprofile" ]]; then
- p10k_instant_prompt="${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
- [[ -r "$p10k_instant_prompt" ]] && source "$p10k_instant_prompt"
-fi
-
axzsh_handle_stage "$script_name" "$script_type"
# Clean up ...
unfunction axzsh_handle_stage axzsh_load_plugin
unset script_name script_type
+
+# Hints for external installers:
+# - iTerm2: DON'T install "iterm2_shell_integration"!
#!/usr/bin/env zsh
#
# AX-ZSH: Alex' Modular ZSH Configuration
-# Copyright (c) 2015-2017 Alexander Barton <alex@barton.de>
+# Copyright (c) 2015-2022 Alexander Barton <alex@barton.de>
#
source "$AXZSH/core/11_terminal/11_terminal.zshrc" || exit 1
-unset VERBOSE
+unset VERBOSE ONE_LINE
while [[ $# -gt 0 ]]; do
case "$1" in
+ "-1")
+ ONE_LINE=1
+ ;;
"-v")
VERBOSE=1
;;
*)
- echo "Usage: ttyinfo [-v]" >&2
+ echo "Usage: ttyinfo [-1] [-v]" >&2
exit 1
esac
shift
done
-print -Pn -- "$fg[white]$FX[bold]$(hostname)$FX[no-bold] "
+print -Pn -- "$fg[white]$FX[bold]$SHORT_HOST$FX[no-bold] "
print -Pn -- "$fg[yellow]$(tty)$FX[reset], "
print -Pn -- "$fg[green]$FX[underline]${TERM:-?}$FX[reset] "
-print -Pn -- "(${COLUMNS:-?}x${LINES:-?}); "
-print -Pn -- "$fg[white]LANG=${LANG:-?}$FX[reset]"
+print -Pn -- "(${COLUMNS:-?}x${LINES:-?})"
+[[ -n "$TERM_PROGRAM" ]] && print -Pn -- "; $fg[green]$TERM_PROGRAM$FX[reset]"
+[[ -n "$$TERM_PROGRAM_VERSION" ]] && print -Pn -- " $TERM_PROGRAM_VERSION"
+print -Pn -- "$FX[reset]"
echo
+[[ -n "$ONE_LINE" ]] && return 0
+
+typeset -i max=${COLUMNS:-80}
+typeset -i col=0
+for key (
+ LANG
+ LC_ALL
+ LC_ADDRESS
+ LC_COLLATE
+ LC_CTYPE
+ LC_IDENTIFICATION
+ LC_MEASUREMENT
+ LC_MESSAGES
+ LC_MONETARY
+ LC_NAME
+ LC_NUMERIC
+ LC_PAPER
+ LC_TELEPHONE
+ LC_TIME
+ -
+ COLORTERM
+ CLICOLOR
+ TERM_COLORS
+ -
+ DISPLAY
+); do
+ if [[ $key == "-" ]]; then
+ [[ $col -gt 0 ]] && echo
+ col=0
+ continue
+ fi
+
+ [[ "${(P)key-UNSET}" = "UNSET" ]] && continue
+ val=${(P)key}
+
+ col=$(( $col + ${#key} + ${#val} + 5 ))
+ if [[ $col -gt $max ]]; then
+ echo
+ col=$(( ${#key} + ${#val} + 5 ))
+ fi
+
+ print -Pn -- "$key=\"$fg[cyan]$val$FX[reset]\"; "
+done
+[[ $col -gt 0 ]] && echo
+
[[ -z "$VERBOSE" ]] && return 0
check_function_result() {
#!/usr/bin/env zsh
#
# AX-ZSH: Alex' Modular ZSH Configuration
-# Copyright (c) 2015-2020 Alexander Barton <alex@barton.de>
+# Copyright (c) 2015-2023 Alexander Barton <alex@barton.de>
#
-# Include "ax-common.sh", if available:
-for dir ("$HOME/lib" "$HOME/.ax" /usr/local /opt/ax /usr); do
- [[ -z "$ax_common_sourced" ]] || break
- ax_common="${dir}/lib/ax/ax-common.sh"
- [[ -r "$ax_common" ]] && source "$ax_common"
-done
-if [[ -z "$ax_common_sourced" ]]; then
- function ax_msg {
- shift
- echo "$@"
- }
- function ax_error {
- ax_msg 2 "$@" >&2
- }
-fi
-unset dir ax_common ax_common_sourced
+# Embedded ax-common compatibility functions ...
+function ax_msg {
+ case "$1" in
+ "0") c="32"; ;;
+ "1") c="33"; ;;
+ "2") c="31"; ;;
+ "-") c="1"; ;;
+ *) c="0"; ;;
+ esac
+ shift
+ printf "\e[${c}m%s\e[0m\n" "$@"
+}
+function ax_error {
+ ax_msg 2 "$@" >&2
+}
function Version {
echo "ax-zsh -- Modular configuration system for the Z shell (ZSH)"
- echo "Copyright (c) 2015-2019 Alexander Barton <alex@barton.de>."
+ echo "Copyright (c) 2015-2023 Alexander Barton <alex@barton.de>."
echo "Licensed under the terms of the MIT license, see LICENSE.md for details."
echo "Homepage: <https://github.com/alexbarton/ax-zsh>"
+ echo
+ echo "Installation prefix: $AXZSH"
+ echo -n "Version: "
if [[ -d "$AXZSH/.git" && -n "$commands[git]" ]]; then
- echo -n "Version: Git ID "
+ echo -n "Git Commit-ID "
( cd "$AXZSH" && git describe --always )
+ else
+ echo "unknown"
+ fi
+ echo -n "Active theme: "
+ if [[ -n "$AXZSH_THEME" ]]; then
+ echo "${AXZSH_THEME:A:t:r}"
+ else
+ echo "unknown"
fi
echo
exit 0
echo " Disable plugin(s)."
echo " list-enabled"
echo " List enabled plugins."
+ echo " plugin-help"
+ echo " Show help text for a plugin (when provided by the plugin)."
echo
echo " reset-plugins"
echo " Reset active plugins to the default set."
echo " check-plugins"
echo " Detect plugins which are \"useful\" on this system."
echo
- echo " set-theme <name>|-"
+ echo " set-theme {<name>|-}"
echo " Set active theme to <name>, or to the default."
echo
echo " upgrade"
echo " update-caches"
echo " Force rebuild of all cache files."
echo
+ echo " help"
+ echo " Show this help text."
+ echo " version"
+ echo " Show version and setup information."
+ echo
exit 0
}
function UpdatePluginCache {
[[ -r "$AXZSH/cache" ]] || return 0
- [[ "$1" = "-v" ]] && ax_msg - "Updating plugin cache ..."
+ [[ "$1" = "-v" ]] && ax_msg - "Invalidating & updating caches ..."
+
+ if [[ -d "$ZSH_CACHE_DIR" ]]; then
+ [[ "$1" = "-v" ]] && echo "Removing ZSH cache folder ..."
+ rm -fr "$ZSH_CACHE_DIR"
+ fi
+
+ [[ "$1" = "-v" ]] && echo "Removing AX-ZSH cache files ..."
rm -rf \
$AXZSH/cache/ax-io.cache \
$AXZSH/cache/zlogin.cache \
$AXZSH/cache/zprofile.cache \
$AXZSH/cache/zshrc.cache \
|| return 1
- echo "Regenerating cache files ..."
- zsh -ilc '' >/dev/null
+
+ echo "Regenerating AX-ZSH cache ..."
+ [[ -z "$AXZSH_DEBUG" ]] \
+ && AXZSH_PLUGIN_CHECK=1 zsh -ilc '' >/dev/null \
+ || AXZSH_PLUGIN_CHECK=1 zsh -ilc ''
}
function NormalizedPluginName {
- if [[ "$1" =~ "^[[:alnum:]-]+/[[:alnum:]_-]+$" ]]; then
+ if [[ "$1" =~ "^@?[[:alnum:]-]+/[[:alnum:]_.-]+$" ]]; then
echo "${1:gs/\//#}"
elif [[ "$1" =~ "/" ]]; then
echo "${1:t}"
ln -s "$AXZSH/ax.zsh" "$f" \
|| ax_error "Failed to create symbolic link for \"$f\"!"
done
+ if [[ -z "$AXZSH_FPATH" ]]; then
+ echo "AX-ZSH was enabled. Now you should restart your shell, for example like this:"
+ echo "$ exec -l \"\$SHELL\""
+ fi
}
function DisableAXZSH {
function EnablePlugin {
local plugin=$(NormalizedPluginName "$1")
local dir="$AXZSH/active_plugins"
+ local name="$plugin"
if [[ -h "$dir/$plugin" ]]; then
ax_msg 1 "Plugin \"$1\" already active!"
return 1
fi
- if [[ "$1" =~ "^[[:alnum:]-]+/[[:alnum:]_-]+$" ]]; then
+ if [[ "$1" =~ "^@[[:alnum:]-]+/[[:alnum:]_.+-]+$" ]]; then
+ # GitHub plugin repository (like OhMyZsh)
+ local repo="${1##@}"
+ repo="${repo%/*}"
+ mkdir -p "$AXZSH/repos/@$repo"
+ if [[ ! -d "$AXZSH/repos/@$repo/plugins" ]]; then
+ ax_msg - "Cloning \"$repo\" from GitHub ..."
+ git clone --depth=1 "https://github.com/$repo/$repo.git" \
+ "$AXZSH/repos/@$repo" \
+ || ax_error "Failed to clone \"$repo\" repository!"
+ fi
+ plugin="@$repo/plugins/${1#*/}"
+ echo "Trying to enable \"$1\" ..."
+ elif [[ "$1" =~ "^[[:alnum:]-]+/[[:alnum:]_.-]+$" ]]; then
# GitHub plugin
mkdir -p "$AXZSH/repos"
if [[ ! -e "$AXZSH/repos/$plugin" ]]; then
return 0
fi
echo "Trying to enable \"$1\" as plugin ..."
+ elif ! [[ "$1" =~ "^[[:alnum:]_.-]+$" ]]; then
+ ax_error "Invalid plugin name!"
+ return 1
fi
for dname (
mkdir -p "$dir"
if ! (
cd "$dir" || exit 9
- ln -s "$dname" "$PWD"
+ ln -s "$dname" "$PWD/$name"
); then
ax_error "Failed to create link!"
return 1
fi
- ax_msg 0 "Plugin \"$plugin\" enabled."
+ ax_msg 0 "Plugin \"$1\" enabled."
return 0
done
return 0
}
+function PluginHelp {
+ local plugin=$(NormalizedPluginName "$1")
+ local repo_plugin=$(echo "$plugin" | sed -e 's|#|/plugins/|')
+ local plugin_found=
+
+ for plugin_d (
+ "$plugin:A"
+ "$AXZSH/active_plugins/$plugin"
+ "$AXZSH/active_plugins/$repo_plugin"
+ "$AXZSH_PLUGIN_D/$plugin"
+ "$ZSH_CUSTOM/$plugin"
+ "$AXZSH/custom_plugins/$plugin"
+ "$AXZSH/repos/$plugin"
+ "$AXZSH/repos/$repo_plugin"
+ "$AXZSH/plugins/$plugin"
+ "$AXZSH/default_plugins/$plugin"
+ "$AXZSH/core/$plugin"
+ ); do
+ [[ -e "$plugin_d" ]] && plugin_found=1
+ [[ -r "$plugin_d/README.md" ]] || continue
+ less "$plugin_d/README.md"
+ return 0
+ done
+ [[ -n "$plugin_found" ]] \
+ && echo "Plugin \"$1\" found, but no help available!" >&2 \
+ || echo "Plugin \"$1\" not found!" >&2
+ return 1
+}
+
function ResetPlugins {
local dir="$AXZSH/active_plugins"
local r1=0, r2=0
fi
ax_msg - "Upgrading AX-ZSH in \"$AXZSH\" using git(1) ..."
- ( cd "$AXZSH" && git pull --ff-only )
+ (
+ set -e
+ cd "$AXZSH"
+ git pull --ff-only || ax_error "Git pull failed!"
+ git log --pretty=format:"%C(yellow)%h %C(blue)%ar %C(green)%an %Creset%s" ORIG_HEAD..
+ )
}
function UpgradeForeignPlugins {
if [[ -d "$dir/.git" ]]; then
ax_msg - "Upgrading \"$name\" [git] ..."
(
+ set -e
cd "$dir"
- git pull --ff-only || ax_error "Pull failed!"
+ git pull --ff-only || ax_error "Git pull failed!"
+ git log --pretty=format:"%C(yellow)%h %C(blue)%ar %C(green)%an %Creset%s" ORIG_HEAD..
)
else
ax_error "Unknown repository type!"
missing_plugins=()
invalid_plugins=()
+ # Building cache file for all zshrc core files:
+ if ! T=$(mktemp); then
+ ax_error "Failed to create temporary file!"
+ return 1
+ fi
+ for p in $AXZSH/core/*/*.zshrc; do
+ [[ "$(basename "$p")" == "01_zprofile.zshrc" ]] && continue
+ printf "# BEGIN: %s\naxzsh_plugin_init()\n{\n" "$p" >>"$T"
+ cat "$p" >>"$T"
+ printf "}\naxzsh_plugin_init\n# END: %s\n\n" "$p" >>"$T"
+ done
+
ax_msg - "Checking plugins ..."
- for dir ($AXZSH/plugins/*(N)); do
+ for dir ($AXZSH/plugins/[a-z0-9]*(N)); do
plugin=${dir:t}
# Test if plugin is already enabled
- [[ -e "$AXZSH/active_plugins/$plugin" ]] \
- && enabled=" (enabled)" \
- || unset enabled
+ if [[ -e "$AXZSH/active_plugins/$plugin" ]]; then
+ printf ' \e[1;32m+\e[m "\e[1m%s\e[m" ... ' "${plugin}"
+ enabled=1
+ else
+ printf ' \e[1;31m-\e[m "%s" ... ' "${plugin}"
+ unset enabled
+ fi
# Test plugin ...
- printf " - \"%s\"%s ... " "$plugin" "$enabled"
new_plugin=""
- for script ($AXZSH/plugins/$plugin/$plugin.{zshrc,zprofile}); do
+ for script ($AXZSH/plugins/$plugin/$plugin.{zshrc,zprofile,ax-io}); do
[[ -r "$script" ]] || continue
- AXZSH_PLUGIN_CHECK=1 zsh -i -c "source $script"; r=$?
- if [[ $r -eq 0 ]]; then
- new_plugin=$plugin
- break
- fi
+ (
+ AXZSH_PLUGIN_CHECK=1
+ source "$T"
+ axzsh_plugin_fnc() { source "$script" }
+ axzsh_plugin_fnc
+ ); r=$?
+ [[ $r -eq 0 ]] && new_plugin=$plugin
+ break
done
if [[ -n "$new_plugin" ]]; then
detected_plugins+=($new_plugin)
ax_msg 1 "optional."
else
[[ -n "$enabled" ]] && invalid_plugins+=($plugin)
- ax_msg 2 "failed."
+ ax_msg 2 "failed ($r)."
fi
done
+ rm -f "$T"
echo
result=0
[[ $# -eq 0 ]] || Usage
ListEnabledPlugins
;;
+ "plugin-help")
+ [[ $# -eq 1 ]] || Usage
+ PluginHelp "$1"
+ ;;
"reset-plugins")
[[ $# -eq 0 ]] || Usage
ResetPlugins
# AX-ZSH: Alex' Modular ZSH Configuration
-# 01_zprofile.zshrc: Make sure zpfofile files are read
+# 01_zprofile.zshrc: Make sure zprofile files are read
[[ -z "$AXZSH_ZPROFILE_READ" ]] || return
-# No "zprofile" files have been read in already! So most probably this
-# ZSH instance hasn't been called from an ax-zsh enabled ZSH!
+# No "zprofile" (and "ax-io") stage files have been read in already, so looks
+# like this is a non-login shell instance but not a (direct) child of an AX-ZSH
+# enabled login shell! This can happen in graphical terminals not starting a
+# login shell, for example. So most probably some environment configuration is
+# missing and we have to make sure everything is set up properly by reading in
+# the "ax-io" and "zprofile" stages before continuing!
+[[ -n "$AXZSH_DEBUG" ]] && echo "» 01_zprofile.zshrc:"
# Reset some environment variables, that could contain "garbage" ...
unset PS1
-[[ -n "$AXZSH_DEBUG" ]] && echo "» 01_zprofile.zsh:"
-
-if [[ -r "$AXZSH/cache/zprofile.cache" ]]; then
- # Cache file exists, use it!
- [[ -n "$AXZSH_DEBUG" ]] \
- && echo " - Reading cache file \"$AXZSH/cache/zprofile.cache\" ..."
- source "$AXZSH/cache/zprofile.cache"
-else
- # No cache file, so read plugins manually. The "plugin_list" can be
- # empty, when the "zshrc" stage has been read in using the cache file,
- # but there is no cache file for the "zprofile" stage. In that case
- # the "plugin_list" must be assembled right now (see "ax.zsh" file!):
- if [[ -z "$plugin_list" ]]; then
- typeset -U plugin_list
- plugin_list=(
- "$AXZSH/core/"[0-5]*
- "$AXZSH/active_plugins/"*(N)
- "$AXZSH/core/"[6-9]*
- )
- fi
- for plugin ($plugin_list); do
- axzsh_load_plugin "$plugin" "zprofile"
- done
-fi
+axzsh_handle_stage "01_zprofile.zshrc" "ax-io"
+axzsh_handle_stage "01_zprofile.zshrc" "zprofile"
AXZSH_ZPROFILE_READ=2
-[[ -n "$AXZSH_DEBUG" ]] && echo "» 01_zprofile.zsh (end)"
+[[ -n "$AXZSH_DEBUG" ]] && echo "» 01_zprofile.zshrc (end)"
if [[ "$TERM_PROGRAM" == "Apple_Terminal" && "$TERM" != "screen"* ]]; then
axzsh_terminal_set_icon_title "$LOGNAME@$SHORT_HOST"
# Update CWD in Terminal.app
- local url=$(echo "file://$HOSTNAME$PWD" | sed -e 's| |%20|g')
+ local url=$(echo "file://$HOST$PWD" | sed -e 's| |%20|g')
printf '\e]7;%s\a' "$url"
else
axzsh_terminal_set_icon_title "$LOGNAME@$SHORT_HOST:$PWD"
locale="$1:r"
encoding="$1:e"
- if [[ -z "$1" || "$locale" =~ '.*_.*' || ${#locale%%_*} -ne 2 ]]; then
+ if [[ -z "$1" || "$locale" =~ '_' || ${#locale%%_*} -ne 2 ]]; then
echo "$1"
else
locale="${locale:0:2}_${locale:0:2:u}"
# Validate the locale(7) settings in interactive shells and try to mimic the
# tset(1) behaviour.
while true; do
- lc_messages=$(locale 2>/dev/null | fgrep LC_MESSAGES | cut -d'=' -f2)
+ lc_messages=$(locale 2>/dev/null | grep -F LC_MESSAGES | cut -d'=' -f2)
[[ "$lc_messages" = '"C"' && "$LANG" != 'C' && "$LC_ALL" != 'C' ]] && lc_messages=$LANG
lc_messages=$lc_messages:gs/\"//
locale=$lc_messages:r
break
fi
- echo "ax-zsh: unknown/unsupported locale ${lc_messages:-unknown}" >&2
+ echo "ax-zsh: Unknown/unsupported locale \"${lc_messages:-unknown}\"!" >&2
unset locale
while [[ -z "$locale" ]]; do
- if ! read "locale?Locale? "; then
+ if ! read -r "locale?Locale? "; then
echo >&2
break 2
fi
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 20_home.ax-io: Setup (local) home directory
+
+[[ -d "/usr/local/home" && ! -d "/usr/local/home/$LOGNAME" ]] \
+ && mkdir -m 700 "/usr/local/home/$LOGNAME" >/dev/null 2>&1
+
+[[ -w "/usr/local/home/$LOGNAME" ]] \
+ && export LOCAL_HOME="/usr/local/home/$LOGNAME" \
+ || export LOCAL_HOME="$HOME"
+++ /dev/null
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 20_home.zprofile: Setup (local) home directory
-
-[[ -d "/usr/local/home" && ! -d "/usr/local/home/$LOGNAME" ]] \
- && mkdir -m 700 "/usr/local/home/$LOGNAME" >/dev/null 2>&1
-
-[[ -w "/usr/local/home/$LOGNAME" ]] \
- && export LOCAL_HOME="/usr/local/home/$LOGNAME" \
- || export LOCAL_HOME="$HOME"
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 30_env.ax-io: Setup environment
+
+# Setup time zone
+if [[ -z "$TZ" && -r "/etc/timezone" ]]; then
+ TZ=$(<"/etc/timezone") export TZ
+fi
+
+# Validate temporary directory
+if [[ -z "$TMPDIR" || "$TMPDIR" = "/" ]]; then
+ if [[ -n "$XDG_RUNTIME_DIR" && -w "$XDG_RUNTIME_DIR" ]]; then
+ # The "runtime directory" is set for this user, good, so use
+ # it silently as the "temporary directory", too:
+ TMPDIR="$XDG_RUNTIME_DIR"
+ else
+ # Try to find a sane "temporary directory", but warn the user
+ # that this is a best guess only!
+ TMPDIR="$(dirname $(mktemp -ut tmp.XXXXXXXXXX))/"
+ [[ -z "$TMPDIR" || "$TMPDIR" = "/" ]] && TMPDIR="/tmp"
+ user_tmpdir="$TMPDIR$UID"
+ mkdir -p "$user_tmpdir" >/dev/null 2>&1
+ if [[ -w "$user_tmpdir" ]]; then
+ TMPDIR="$user_tmpdir/"
+ chmod 0700 "$TMPDIR"
+ fi
+ echo "Note: \"TMPDIR\" was not set, using \"$TMPDIR\"." >&2
+ unset user_tmpdir
+ fi
+fi
+# Make sure TMPDIR ends in a slash (like on macOS by default): this makes its
+# usage a bit safer ...
+case "$TMPDIR" in
+ */) ;;
+ *) TMPDIR="$TMPDIR/"
+esac
+if [[ ! -w "$TMPDIR" ]]; then
+ echo "Warning: Temporary directory \"$TMPDIR\" is not writable!" >&2
+fi
+export TMPDIR
+
+# TMPDIR is the only one required to be set, but make sure that TMP, TEMP
+# and TEMPDIR are set to the same sane path name when already present in the
+# environment:
+[[ -n "$TMP" ]] && export TMP="$TMPDIR"
+[[ -n "$TEMP" ]] && export TEMP="$TMPDIR"
+[[ -n "$TEMPDIR" ]] && export TEMPDIR="$TMPDIR"
+
+# Setup XDG cache directory
+if [[ -z "$XDG_CACHE_HOME" ]]; then
+ XDG_CACHE_HOME="$LOCAL_HOME/.cache"
+fi
+if [[ ! -d "$XDG_CACHE_HOME" ]]; then
+ mkdir -p "$XDG_CACHE_HOME"
+ chmod 0700 "$XDG_CACHE_HOME"
+fi
+export XDG_CACHE_HOME
+
+# Setup XDG runtime directory
+if [[ -z "$XDG_RUNTIME_DIR" ]]; then
+ XDG_RUNTIME_DIR="$TMPDIR/runtime-dir.$UID"
+fi
+if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
+ mkdir -p "$XDG_RUNTIME_DIR"
+ chmod 0700 "$XDG_RUNTIME_DIR"
+fi
+export XDG_RUNTIME_DIR
+
+# Setup ZSH cache directory
+if [[ -z "$ZSH_CACHE_DIR" ]]; then
+ ZSH_CACHE_DIR="$XDG_CACHE_HOME/zsh"
+fi
+if [[ ! -d "$ZSH_CACHE_DIR" ]]; then
+ mkdir -p "$ZSH_CACHE_DIR"
+ chmod 0700 "$ZSH_CACHE_DIR"
+fi
+export ZSH_CACHE_DIR
+++ /dev/null
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 30_env.zprofile: Setup environment
-
-# Setup time zone
-if [[ -z "$TZ" && -r "/etc/timezone" ]]; then
- TZ=$(<"/etc/timezone") export TZ
-fi
-
-# Setup XDG cache directory
-if [[ -z "$XDG_CACHE_HOME" ]]; then
- XDG_CACHE_HOME="$LOCAL_HOME/.cache"
-fi
-if [[ ! -d "$XDG_CACHE_HOME" ]]; then
- mkdir -p "$XDG_CACHE_HOME"
- chmod 0700 "$XDG_CACHE_HOME"
-fi
-export XDG_CACHE_HOME
-
-# Setup XDG runtime directory
-if [[ -z "$XDG_RUNTIME_DIR" ]]; then
- XDG_RUNTIME_DIR="${TMPDIR:-/tmp/${UID}-runtime-dir}"
-fi
-if [[ ! -d "$XDG_RUNTIME_DIR" ]]; then
- mkdir -p "$XDG_RUNTIME_DIR"
- chmod 0700 "$XDG_RUNTIME_DIR"
-fi
-export XDG_RUNTIME_DIR
-
-# Setup ZSH cache directory
-if [[ -z "$ZSH_CACHE_DIR" ]]; then
- ZSH_CACHE_DIR="$XDG_CACHE_HOME/zsh"
-fi
-if [[ ! -d "$ZSH_CACHE_DIR" ]]; then
- mkdir -p "$ZSH_CACHE_DIR"
- chmod 0700 "$ZSH_CACHE_DIR"
-fi
-export ZSH_CACHE_DIR
# AX-ZSH: Alex' Modular ZSH Configuration
-# 30_env.zshrc: Setup environment
+# 30_env.ax-io: Setup environment
-# Setup TMPDIR. Try to reset TMPDIR (when it is not set but TMP is), which is
-# common in tools like screen(1) because Linux removes some varibes for
-# "setgit" tools (see <https://bugzilla.redhat.com/show_bug.cgi?id=129682#c1>).
-# And therefore this has to be checked here, because inside of screen probably
-# no login shell is started ...
-[[ -z "$TMPDIR" && -n "$TMP" ]] && TMPDIR="$TMP"
-
-# Make sure TMP and TMPDIR become exported when they are set:
-[[ -n "$TMP" ]] && export TMP
-[[ -n "$TMPDIR" ]] && export TMPDIR
+if [[
+ "$TMPDIR" = '/' ||
+ -z "$TMPDIR" ||
+ -z "$XDG_CACHE_HOME" ||
+ -z "$XDG_RUNTIME_DIR" ||
+ -z "$ZSH_CACHE_DIR"
+]]; then
+ # Looks like the environment wasn't set up/exported properly!
+ [[ -n "$AXZSH_DEBUG" ]] && echo 'Note: Fixing up the environment!'
+ . "$AXZSH/core/30_env/30_env.ax-io"
+fi
# AX-ZSH: Alex' Modular ZSH Configuration
# 30_hostname.zprofile: Initialize hostname settings
-# Setup "HOSTNAME" variable
-[[ -z "$HOSTNAME" ]] && HOSTNAME=$( hostname )
+# Setup legacy "HOSTNAME" variable (use "HOST"!)
+[[ -z "$HOSTNAME" ]] && HOSTNAME="$HOST"
export HOSTNAME
# Setup "SHORT_HOST" variable
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 30_path.zprofile: Setup PATH environment
+
+# Set default PATH
+if [[ -x /usr/libexec/path_helper ]]; then
+ eval "$(/usr/libexec/path_helper)"
+else
+ PATH="/usr/sbin:/usr/bin:/sbin:/bin"
+fi
+typeset -Ux PATH
+
+_axzsh_setup_path() {
+ # Prepend additional search paths
+ for d (
+ /Developer/usr/bin
+ /usr/ucb
+ /usr/pkg/bin
+ /usr/local/bin
+ /usr/local/sbin
+ /opt/*/bin(NOn)
+ /opt/*/sbin(NOn)
+ ~/.gem/ruby/*/bin(NOn)
+ ~/.go/bin
+ ~/.cargo/bin
+ ~/.local/bin
+ ~/bin
+ ~/sbin
+ ~/Applications
+ ); do
+ [[ -d "$d" ]] && path=("$d" $path)
+ done
+
+ # Append additional search paths
+ for d (
+ /usr/X11/bin
+ /usr/local/games
+ /usr/games
+ ); do
+ [[ -d "$d" ]] && path=($path "$d")
+ done
+}
+
+# Prepend and append search paths (in a special order!)
+_axzsh_setup_path
+
+# Set default MANPATH
+MANPATH="$(manpath -q)" 2>/dev/null
+if [[ $? -ne 0 ]]; then
+ for d (
+ ~/share/man
+ ~/man
+ /opt/*/share/man(NOn)
+ /opt/*/man(NOn)
+ /usr/share/man
+ /usr/local/share/man
+ ); do
+ [[ -d "$d" ]] && manpath=($manpath "$d")
+ done
+fi
+typeset -Ux MANPATH
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 50_axzsh.zshrc: Initialize AX-ZSH
+
+function axzshctl() {
+ AXZSH_THEME="$AXZSH_THEME" zsh "$AXZSH/bin/axzshctl" "$@" || return $?
+
+ if [[ "$1" = "disable" ]]; then
+ unset AXZSH AXZSH_FPATH AXZSH_ZLOGIN_READ AXZSH_ZPROFILE_READ
+ fi
+
+ case "$1" in
+ "disable"*|"enable"*|"reset"*|"set"*|"up"*)
+ # Command which potentially "changed state".
+ if [[ -o login ]]; then
+ echo "Restarting login shell ..."
+ exec -l "$SHELL"
+ else
+ echo "Restarting shell ..."
+ exec "$SHELL"
+ fi
+ ;;
+ esac
+ return 0
+}
--- /dev/null
+#compdef axzshctl
+
+_axzshctl() {
+ _arguments \
+ '1: :((
+ enable\:"Enable AX-ZSH."
+ disable\:"Disable AX-ZSH."
+ enable-plugin\:"Enable plugin(s)."
+ disable-plugin\:"Disable plugin(s)."
+ list-enabled\:"List enabled plugin(s)."
+ plugin-help\:"Show help text for a plugin."
+ reset-plugins\:"Reset active plugins to the default set."
+ enable-default-plugins\:"Enable all default plugins."
+ check-plugins\:"Check \"useful\" plugins."
+ set-theme\:"Set active theme."
+ upgrade\:"Upgrade AX-ZSH installation (requires Git)."
+ update-caches\:"Force rebuild of all cache files."
+ version\:"Show version and setup information."
+ help\:"Show help for the axzshctl command."
+ ))' \
+ '*: :->args'
+#
+ case "$state" in
+ 'args')
+ case "$words[2]" in
+ "enable-plugin"|"plugin-help")
+ compadd "$@" -- \
+ "$AXZSH"/plugins/*(/:t) \
+ "$AXZSH"/custom_plugins/*(N/:t) \
+ "$AXZSH"/repos/*(/:t:s/#/\\/)
+ for r in "$AXZSH"/repos/@*(N/); do
+ b=(echo $r(:t))
+ compadd "$@" -- \
+ $(echo $r/plugins/*(N:t) | sed -E "s/(^| )/ $b\//g")
+ done
+ ;;
+ "disable-plugin")
+ compadd "$@" -- \
+ "$AXZSH"/active_plugins/*(:t:s/#/\\/)
+ ;;
+ "set-theme")
+ compadd "$@" -- "-" \
+ "$AXZSH"/themes/*.axzshtheme(:r:t) \
+ "$AXZSH"/custom_themes/*.axzshtheme(N:r:t) \
+ "$AXZSH"/custom_themes/*.zsh-theme(N:r:t) \
+ "$AXZSH"/repos/*/*.axzshtheme(N:r:t) \
+ "$AXZSH"/repos/*/*.zsh-theme(N:r:t)
+ ;;
+ esac
+ ;;
+ esac
+}
+
+_axzshctl "$@"
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 50_completion.zshrc: Setup completion
+
+autoload -Uz compinit
+
+zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
+
+zstyle ':completion:*' accept-exact '*(N)'
+zstyle ':completion:*' list-colors ''
+zstyle ':completion:*' menu select
+zstyle ':completion:*' special-dirs true
+zstyle ':completion:*' group-name ''
+zstyle ':completion:*' squeeze-slashes true
+
+# Messages
+zstyle ':completion:*:corrections' format '%B%d%b (%e errors)'
+zstyle ':completion:*:descriptions' format '%B%d%b'
+zstyle ':completion:*:messages' format '%B%F{yellow}%d%f%b'
+zstyle ':completion:*:warnings' format '%B%F{red}No matches found!%f%b'
+
+# Use caching so that commands like apt and dpkg completions are useable
+zstyle ':completion:*' use-cache on
+zstyle ':completion:*' cache-path "$ZSH_CACHE_DIR"
+
+# Manual pages
+zstyle ':completion:*:manuals' separate-sections true
+zstyle ':completion:*:manuals.*' insert-sections true
+
+# Don't complete uninteresting users
+zstyle ':completion:*:*:*:users' ignored-patterns \
+ adm amanda amavis apache arpwatch at avahi avahi-autoipd backup \
+ beaglidx bin bind cacti canna clamav cockpit-ws cockpit-wsinstance \
+ colord daapd daemon dbus distcache dnsmasq dovecot dovenull fax \
+ fetchmail firebird ftp games gdm gkrellmd gnats gopher hacluster \
+ haldaemon halt hsqldb ident irc junkbust kdm ldap libuuid libvirt-qemu \
+ list logcheck lp mail mailman mailnull man messagebus mldonkey mysql \
+ nagios named netdata netdump news nfsnobody nobody nscd ntp nut nx \
+ obsrun oident openvpn operator pcap polkitd postfix postgres postgrey \
+ privoxy proxy pvm quagga radvd rpc rpcuser rpm rslsync rtkit rwhod \
+ sbuild scard shutdown squid sshd statd stunnel4 svn sync sys \
+ systemd-coredump systemd-journal-remote systemd-network systemd-resolve \
+ systemd-timesync telnetd telnetd-ssl tftp thelounge usbmux uucp uuidd \
+ vcsa www-data wwwrun xfs xrdp zabbix \
+ '_*' '*$' 'debian-*' 'Debian-*'
+
+# Ignore completion functions
+zstyle ':completion:*:functions' ignored-patterns '_*'
+
+# Show ignore matches, if we really want this
+zstyle '*' single-ignored show
+
+# Save the location of the current completion dump file.
+if [[ -z "$ZSH_COMPDUMP" ]]; then
+ ZSH_COMPDUMP="$ZSH_CACHE_DIR/zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
+fi
+
+# Try to add all folders possibly containing completion functions to the fpath
+# before calling compinit. See <https://github.com/ohmyzsh/ohmyzsh/issues/4614>
+# for a discussion of this topic, for example. It boils down to:
+# - We have to call compinit early,
+# - but plugins can add completions later, that won't be found ...
+# (GENCOMPL_FPATH is used by RobSis/zsh-completion-generator)
+[[ -n "$GENCOMPL_FPATH" ]] && fpath+=($GENCOMPL_FPATH)
+fpath+=("$AXZSH/active_plugins/"*/completions(N))
+fpath+=("$AXZSH/active_plugins/"*/src(N))
+
+# Initialize ZSH completion system
+if [[ "$ZSH_DISABLE_COMPFIX" = "true" ]]; then
+ compinit -u -d "$ZSH_COMPDUMP"
+else
+ compinit -d "$ZSH_COMPDUMP"
+fi
+++ /dev/null
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 40_path.zprofile: Setup PATH environment
-
-# Set default PATH
-if [[ -x /usr/libexec/path_helper ]]; then
- eval "$(/usr/libexec/path_helper)"
-else
- PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-fi
-typeset -Ux PATH
-
-# Prepend additional search paths
-for d (
- /Developer/usr/bin
- /usr/ucb
- /usr/pkg/bin
- /usr/local/bin
- /usr/local/sbin
- /opt/*/bin(NOn)
- /opt/*/sbin(NOn)
- /home/linuxbrew/.linuxbrew/bin
- /home/linuxbrew/.linuxbrew/sbin
- ~/.linuxbrew/bin
- ~/.linuxbrew/sbin
- ~/.gem/ruby/*/bin(NOn)
- ~/.local/bin
- ~/bin
- ~/sbin
- ~/Applications
-); do
- [ -d "$d" ] && path=("$d" $path)
-done
-
-# Append additional search paths
-for d (
- /usr/X11/bin
- /usr/local/games
- /usr/games
-); do
- [ -d "$d" ] && path=($path "$d")
-done
-
-# Set default MANPATH
-MANPATH="$(manpath -q)" 2>/dev/null
-if [[ $? -ne 0 ]]; then
- for d (
- ~/share/man
- ~/man
- ~/.linuxbrew/share/man
- /home/linuxbrew/.linuxbrew/share/man
- /opt/*/share/man(NOn)
- /opt/*/man(NOn)
- /usr/share/man
- /usr/local/share/man
- ); do
- [ -d "$d" ] && manpath=($manpath "$d")
- done
-fi
-typeset -Ux MANPATH
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 50_prompt.zshrc: Setup default prompts
+
+# Some dummy functions (used by some OhMyZsh themes, for example) ...
+git_prompt_info(){ true; }
+git_prompt_status(){ true; }
+rvm_prompt_info(){ true; }
+
+# Logname ("user name")
+
+ZSH_THEME_LOGNAME_PROMPT_PREFIX_SPACING=""
+if (( $UID == 0 )); then
+ ZSH_THEME_LOGNAME_PROMPT_PREFIX="%{$fg_no_bold[red]%}" \
+ ZSH_THEME_LOGNAME_PROMPT_SUFFIX="%{$reset_color%}"
+else
+ ZSH_THEME_LOGNAME_PROMPT_PREFIX=""
+ ZSH_THEME_LOGNAME_PROMPT_SUFFIX=""
+fi
+ZSH_THEME_LOGNAME_PROMPT_SUFFIX_SPACING="@"
+
+function axzsh_logname_prompt_root() {
+ (( $UID == 0 )) || return 1
+ return 0
+}
+
+function axzsh_logname_prompt_yn() {
+ local func
+ for func ($axzsh_logname_prompt_functions); do
+ $func || continue
+ echo "${ZSH_THEME_LOGNAME_PROMPT_PREFIX_SPACING}${ZSH_THEME_LOGNAME_PROMPT_PREFIX}${1:-$LOGNAME}${ZSH_THEME_LOGNAME_PROMPT_SUFFIX}${ZSH_THEME_LOGNAME_PROMPT_SUFFIX_SPACING}"
+ return
+ done
+}
+
+# Hostname
+
+ZSH_THEME_HOSTNAME_PROMPT_PREFIX_SPACING=""
+ZSH_THEME_HOSTNAME_PROMPT_PREFIX=""
+ZSH_THEME_HOSTNAME_PROMPT_SUFFIX=""
+ZSH_THEME_HOSTNAME_PROMPT_SUFFIX_SPACING=":"
+
+function axzsh_hostname_prompt_root() {
+ (( $UID == 0 )) || return 1
+ return 0
+}
+
+function axzsh_hostname_prompt_yn() {
+ local func
+ for func ($axzsh_hostname_prompt_functions); do
+ $func || continue
+ echo "${ZSH_THEME_HOSTNAME_PROMPT_PREFIX_SPACING}${ZSH_THEME_HOSTNAME_PROMPT_PREFIX}${1:-$SHORT_HOST}${ZSH_THEME_HOSTNAME_PROMPT_SUFFIX}${ZSH_THEME_HOSTNAME_PROMPT_SUFFIX_SPACING}"
+ return
+ done
+}
+
+axzsh_hostname_prompt_functions=()
+
+# VCS
+
+if axzsh_is_utf_terminal; then
+ clean="✔"; dirty="✘"; ahead="→"; behind="←"
+else
+ clean="+"; dirty="x"; ahead=">"; behind="<"
+fi
+
+ZSH_THEME_VCS_PROMPT_PREFIX_SPACING="("
+ZSH_THEME_VCS_PROMPT_PREFIX="%{$fg_no_bold[yellow]%}"
+ZSH_THEME_VCS_PROMPT_SUFFIX="%{$fg[default]%}"
+ZSH_THEME_VCS_PROMPT_SUFFIX_SPACING=")"
+
+ZSH_THEME_VCS_PROMPT_CLEAN=" %{$fg_no_bold[green]%}$clean%{$fg[default]%}"
+ZSH_THEME_VCS_PROMPT_DIRTY=" %{$fg_no_bold[red]%}$dirty%{$fg[default]%}"
+ZSH_THEME_VCS_PROMPT_AHEAD="%{$fg_no_bold[cyan]%}$ahead%{$fg[default]%}"
+ZSH_THEME_VCS_PROMPT_BEHIND="%{$fg_no_bold[blue]%}$behind%{$fg[default]%}"
+
+unset clean dirty ahead behind
+
+function axzsh_vcs_prompt() {
+ local func
+ local p
+ for func ($axzsh_vcs_prompt_functions); do
+ p=$( $func ) || continue
+ echo "${ZSH_THEME_VCS_PROMPT_PREFIX_SPACING}${p}${ZSH_THEME_VCS_PROMPT_SUFFIX_SPACING}"
+ return
+ done
+}
+
+axzsh_vcs_prompt_functions=()
+
+# Prompt
+
+ZSH_THEME_PROMPT="$"
+ZSH_THEME_PROMPT_ROOT="#"
+
+ZSH_THEME_PROMPT_PREFIX_SPACING=""
+ZSH_THEME_PROMPT_PREFIX=""
+ZSH_THEME_PROMPT_ROOT_PREFIX=""
+ZSH_THEME_PROMPT_SUFFIX=""
+ZSH_THEME_PROMPT_SUFFIX_SPACING=""
+
+function axzsh_prompt() {
+ local p
+ (( $UID == 0 )) \
+ && p="${ZSH_THEME_PROMPT_ROOT_PREFIX}${ZSH_THEME_PROMPT_ROOT}" \
+ || p="${ZSH_THEME_PROMPT_PREFIX}${ZSH_THEME_PROMPT}"
+ echo "${ZSH_THEME_PROMPT_PREFIX_SPACING}${p}${ZSH_THEME_PROMPT_SUFFIX}${ZSH_THEME_PROMPT_SUFFIX_SPACING}"
+}
+
+# Options and defaults
+
+setopt PROMPT_SUBST
+++ /dev/null
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 50_axzsh.zshrc: Initialize AX-ZSH
-
-function axzshctl() {
- zsh "$AXZSH/bin/axzshctl" "$@" || return $?
-
- case "$1" in
- "disable"*|"enable"*|"reset"*|"set"*|"up"*)
- # Command which potentially "changed state".
- if [[ -o login ]]; then
- echo "Restarting login shell ..."
- exec -l "$SHELL"
- else
- echo "Restarting shell ..."
- exec "$SHELL"
- fi
- ;;
- esac
- return 0
-}
+++ /dev/null
-#compdef axzshctl
-
-_axzshctl() {
- _arguments \
- '1: :((
- enable\:"Enable AX-ZSH."
- disable\:"Disable AX-ZSH."
- enable-plugin\:"Enable plugin(s)."
- disable-plugin\:"Disable plugin(s)."
- list-enabled\:"List enabled plugin(s)."
- reset-plugins\:"Reset active plugins to the default set."
- enable-default-plugins\:"Enable all default plugins."
- check-plugins\:"Check \"useful\" plugins."
- set-theme\:"Set active theme."
- upgrade\:"Upgrade AX-ZSH installation (requires Git)."
- update-caches\:"Force rebuild of all cache files."
- ))' \
- '*: :->args'
-#
- case "$state" in
- 'args')
- case "$words[2]" in
- "enable-plugin"|"disable-plugin")
- compadd "$@" -- \
- "$AXZSH"/plugins/*(/:t) \
- "$AXZSH"/custom_plugins/*(N/:t) \
- "$AXZSH"/repos/*(/:t:s/#/\\/)
- ;;
- "set-theme")
- compadd "$@" -- "-" \
- "$AXZSH"/themes/*.axzshtheme(:r:t) \
- "$AXZSH"/custom_themes/*.axzshtheme(N:r:t) \
- "$AXZSH"/repos/*/*.zsh-theme(N:r:t)
- ;;
- esac
- ;;
- esac
-}
-
-_axzshctl "$@"
+++ /dev/null
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 50_completion.zshrc: Setup completion
-
-autoload -Uz compinit
-
-zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
-
-zstyle ':completion:*' accept-exact '*(N)'
-zstyle ':completion:*' list-colors ''
-zstyle ':completion:*' menu select
-zstyle ':completion:*' special-dirs true
-zstyle ':completion:*' group-name ''
-zstyle ':completion:*' squeeze-slashes true
-
-# Messages
-zstyle ':completion:*:corrections' format '%B%d%b (%e errors)'
-zstyle ':completion:*:descriptions' format '%B%d%b'
-zstyle ':completion:*:messages' format '%B%F{yellow}%d%f%b'
-zstyle ':completion:*:warnings' format '%B%F{red}No matches found!%f%b'
-
-# Use caching so that commands like apt and dpkg completions are useable
-zstyle ':completion:*' use-cache on
-zstyle ':completion:*' cache-path "$ZSH_CACHE_DIR"
-
-# Manual pages
-zstyle ':completion:*:manuals' separate-sections true
-zstyle ':completion:*:manuals.*' insert-sections true
-
-# Don't complete uninteresting users
-zstyle ':completion:*:*:*:users' ignored-patterns \
- adm amanda amavis apache arpwatch at avahi avahi-autoipd backup \
- beaglidx bin bind cacti canna clamav cockpit-ws cockpit-wsinstance \
- colord daapd daemon dbus distcache dnsmasq dovecot dovenull fax \
- fetchmail firebird ftp games gdm gkrellmd gnats gopher hacluster \
- haldaemon halt hsqldb ident irc junkbust kdm ldap libuuid libvirt-qemu \
- list logcheck lp mail mailman mailnull man messagebus mldonkey mysql \
- nagios named netdata netdump news nfsnobody nobody nscd ntp nut nx \
- obsrun oident openvpn operator pcap polkitd postfix postgres postgrey \
- privoxy proxy pvm quagga radvd rpc rpcuser rpm rslsync rtkit rwhod \
- sbuild scard shutdown squid sshd statd stunnel4 svn sync sys \
- systemd-coredump systemd-journal-remote systemd-network systemd-resolve \
- systemd-timesync telnetd telnetd-ssl tftp thelounge usbmux uucp uuidd \
- vcsa www-data wwwrun xfs xrdp zabbix \
- '_*' '*$' 'debian-*' 'Debian-*'
-
-# Ignore completion functions
-zstyle ':completion:*:functions' ignored-patterns '_*'
-
-# Show ignore matches, if we really want this
-zstyle '*' single-ignored show
-
-# Save the location of the current completion dump file.
-if [[ -z "$ZSH_COMPDUMP" ]]; then
- ZSH_COMPDUMP="$ZSH_CACHE_DIR/zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
-fi
-
-# Initialize ZSH completion system
-compinit -d "$ZSH_COMPDUMP"
--- /dev/null
+# # AX-ZSH: Alex' Modular ZSH Configuration
+# 50_path.zprofile: Fix PATH environment after plugins ran
+
+# Prepend and append search paths (in a special order!)
+_axzsh_setup_path
+unfunction _axzsh_setup_path
+
+typeset -Ux PATH MANPATH
+++ /dev/null
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 50_prompt.zshrc: Setup default prompts
-
-# Some dummy functions (used by some OhMyZsh themes, for example) ...
-git_prompt_info(){ true; }
-git_prompt_status(){ true; }
-rvm_prompt_info(){ true; }
-
-# Logname ("user name")
-
-ZSH_THEME_LOGNAME_PROMPT_PREFIX_SPACING=""
-if (( $UID == 0 )); then
- ZSH_THEME_LOGNAME_PROMPT_PREFIX="%{$fg_no_bold[red]%}" \
- ZSH_THEME_LOGNAME_PROMPT_SUFFIX="%{$reset_color%}"
-else
- ZSH_THEME_LOGNAME_PROMPT_PREFIX=""
- ZSH_THEME_LOGNAME_PROMPT_SUFFIX=""
-fi
-ZSH_THEME_LOGNAME_PROMPT_SUFFIX_SPACING="@"
-
-function ax_logname_prompt_root() {
- (( $UID == 0 )) || return 1
- return 0
-}
-
-function ax_logname_prompt_yn() {
- local func
- for func ($ax_logname_prompt_functions); do
- $func || continue
- echo "${ZSH_THEME_LOGNAME_PROMPT_PREFIX_SPACING}${ZSH_THEME_LOGNAME_PROMPT_PREFIX}${1:-$LOGNAME}${ZSH_THEME_LOGNAME_PROMPT_SUFFIX}${ZSH_THEME_LOGNAME_PROMPT_SUFFIX_SPACING}"
- return
- done
-}
-
-ax_logname_prompt_functions=(ax_logname_prompt_root)
-
-# Hostname
-
-ZSH_THEME_HOSTNAME_PROMPT_PREFIX_SPACING=""
-ZSH_THEME_HOSTNAME_PROMPT_PREFIX=""
-ZSH_THEME_HOSTNAME_PROMPT_SUFFIX=""
-ZSH_THEME_HOSTNAME_PROMPT_SUFFIX_SPACING=":"
-
-function ax_hostname_prompt_root() {
- (( $UID == 0 )) || return 1
- return 0
-}
-
-function ax_hostname_prompt_yn() {
- local func
- for func ($ax_hostname_prompt_functions); do
- $func || continue
- echo "${ZSH_THEME_HOSTNAME_PROMPT_PREFIX_SPACING}${ZSH_THEME_HOSTNAME_PROMPT_PREFIX}${1:-$SHORT_HOST}${ZSH_THEME_HOSTNAME_PROMPT_SUFFIX}${ZSH_THEME_HOSTNAME_PROMPT_SUFFIX_SPACING}"
- return
- done
-}
-
-ax_hostname_prompt_functions=()
-
-# VCS
-
-if axzsh_is_utf_terminal; then
- clean="✔"; dirty="✘"; ahead="→"; behind="←"
-else
- clean="+"; dirty="x"; ahead=">"; behind="<"
-fi
-
-ZSH_THEME_VCS_PROMPT_PREFIX_SPACING="("
-ZSH_THEME_VCS_PROMPT_PREFIX="%{$fg_no_bold[yellow]%}"
-ZSH_THEME_VCS_PROMPT_SUFFIX="%{$fg[default]%}"
-ZSH_THEME_VCS_PROMPT_SUFFIX_SPACING=")"
-
-ZSH_THEME_VCS_PROMPT_CLEAN=" %{$fg_no_bold[green]%}$clean%{$fg[default]%}"
-ZSH_THEME_VCS_PROMPT_DIRTY=" %{$fg_no_bold[red]%}$dirty%{$fg[default]%}"
-ZSH_THEME_VCS_PROMPT_AHEAD="%{$fg_no_bold[cyan]%}$ahead%{$fg[default]%}"
-ZSH_THEME_VCS_PROMPT_BEHIND="%{$fg_no_bold[blue]%}$behind%{$fg[default]%}"
-
-unset clean dirty ahead behind
-
-function ax_vcs_prompt() {
- local func
- local p
- for func ($ax_vcs_prompt_functions); do
- p=$( $func ) || continue
- echo "${ZSH_THEME_VCS_PROMPT_PREFIX_SPACING}${p}${ZSH_THEME_VCS_PROMPT_SUFFIX_SPACING}"
- return
- done
-}
-
-ax_vcs_prompt_functions=()
-
-# Prompt
-
-ZSH_THEME_PROMPT="$"
-ZSH_THEME_PROMPT_ROOT="#"
-
-ZSH_THEME_PROMPT_PREFIX_SPACING=""
-ZSH_THEME_PROMPT_PREFIX=""
-ZSH_THEME_PROMPT_ROOT_PREFIX=""
-ZSH_THEME_PROMPT_SUFFIX=""
-ZSH_THEME_PROMPT_SUFFIX_SPACING=""
-
-function ax_prompt() {
- local p
- (( $UID == 0 )) \
- && p="${ZSH_THEME_PROMPT_ROOT_PREFIX}${ZSH_THEME_PROMPT_ROOT}" \
- || p="${ZSH_THEME_PROMPT_PREFIX}${ZSH_THEME_PROMPT}"
- echo "${ZSH_THEME_PROMPT_PREFIX_SPACING}${p}${ZSH_THEME_PROMPT_SUFFIX}${ZSH_THEME_PROMPT_SUFFIX_SPACING}"
-}
-
-# Options and defaults
-
-setopt PROMPT_SUBST
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 80_local_config.ax-io: Read local configuration
+
+if [[ -r "$HOME/.zprofile.local" ]]; then
+ [[ -n "$AXZSH_DEBUG" ]] && echo "» $HOME/.zprofile.local:"
+ source "$HOME/.zprofile.local"
+ [[ -n "$AXZSH_DEBUG" ]] && echo "» $HOME/.zprofile.local (end)"
+fi
+
+if [[ -r "/var/lib/$HOST/zprofile" ]]; then
+ [[ -n "$AXZSH_DEBUG" ]] && echo "» /var/lib/$HOST/zprofile:"
+ source "/var/lib/$HOST/zprofile"
+ [[ -n "$AXZSH_DEBUG" ]] && echo "» /var/lib/$HOST/zprofile (end)"
+elif [[ -r "/var/lib/$HOST/profile" ]]; then
+ [[ -n "$AXZSH_DEBUG" ]] && echo "» /var/lib/$HOST/profile:"
+ source "/var/lib/$HOST/profile"
+ [[ -n "$AXZSH_DEBUG" ]] && echo "» /var/lib/$HOST/profile (end)"
+fi
+++ /dev/null
-# AX-ZSH: Alex' Modular ZSH Configuration
-# 80_local_config.zprofile: Read local configuration
-
-if [[ -r "$HOME/.zprofile.local" ]]; then
- [[ -n "$AXZSH_DEBUG" ]] && echo "» $HOME/.zprofile.local:"
- source "$HOME/.zprofile.local"
- [[ -n "$AXZSH_DEBUG" ]] && echo "» $HOME/.zprofile.local (end)"
-fi
-
-if [[ -r "/var/lib/$HOST/zprofile" ]]; then
- [[ -n "$AXZSH_DEBUG" ]] && echo "» /var/lib/$HOST/zprofile:"
- source "/var/lib/$HOST/zprofile"
- [[ -n "$AXZSH_DEBUG" ]] && echo "» /var/lib/$HOST/zprofile (end)"
-elif [[ -r "/var/lib/$HOST/profile" ]]; then
- [[ -n "$AXZSH_DEBUG" ]] && echo "» /var/lib/$HOST/profile:"
- source "/var/lib/$HOST/profile"
- [[ -n "$AXZSH_DEBUG" ]] && echo "» /var/lib/$HOST/profile (end)"
-fi
# 99_cleanup.zlogin: Don't pollute the namespace, remove variables/functions/...
for func (
- ax_hostname_prompt_root
- ax_hostname_prompt_yn
- ax_logname_prompt_root
- ax_logname_prompt_yn
- ax_prompt
+ axzsh_hostname_prompt_root
+ axzsh_hostname_prompt_yn
+ axzsh_logname_prompt_root
+ axzsh_logname_prompt_yn
+ axzsh_prompt
); do
unfunction $func 2>/dev/null
done
-for func ($ax_logname_prompt_functions); do
+for func ($axzsh_logname_prompt_functions); do
unfunction $func 2>/dev/null
done
-unset ax_logname_prompt_functions
+unset axzsh_logname_prompt_functions
-for func ($ax_hostname_prompt_functions); do
+for func ($axzsh_hostname_prompt_functions); do
unfunction $func 2>/dev/null
done
-unset ax_hostname_prompt_functions
+unset axzsh_hostname_prompt_functions
# Try to map OhMyZsh theme Environment ...
[[ -n "$ZSH_THEME_GIT_PROMPT_AHEAD" ]] \
# AX-ZSH: Alex' Modular ZSH Configuration
-# 99_zlogin.zshrc: Make sure zpfofile files are read
+# 99_zlogin.zshrc: Make sure zlogin files are read
[[ "$AXZSH_ZPROFILE_READ" = "2" ]] || return
-# No "zlogin" files have been read in already! So most probably this
-# ZSH instance hasn't been called from an ax-zsh enabled ZSH!
+# AXZSH_ZPROFILE_READ is set to 2 when the "ax-io" and "zprofile" were caught
+# up because this is not a login shell and the environment was missing. In this
+# case the "zlogin" stage will be missing in the end as well and therefore we
+# run the "zlogin" stage manually, too.
+[[ -n "$AXZSH_DEBUG" ]] && echo "» 99_zlogin.zshrc:"
-[[ -n "$AXZSH_DEBUG" ]] && echo "» 99_zlogin.zsh:"
-for plugin ($plugin_list); do
- axzsh_load_plugin "$plugin" "zlogin"
-done
+axzsh_handle_stage "99_zlogin.zshrc" "zlogin"
AXZSH_ZLOGIN_READ=2
-[[ -n "$AXZSH_DEBUG" ]] && echo "» 99_zlogin.zsh (end)"
+
+[[ -n "$AXZSH_DEBUG" ]] && echo "» 99_zlogin.zshrc (end)"
+++ /dev/null
-# AX-ZSH: Alex' Modular ZSH Configuration
-# bash_completion.zshrc: Setup bash(1) completion
-
-# Define some "dummy functions"
-_init_completion() { return 0 }
-
-autoload -Uz bashcompinit || return 1
-bashcompinit
-
-for dir (
- /etc/bash_completion.d
- /usr/local/etc/bash_completion.d
-); do
- # Read in all completion functions ...
- for file ("$dir/"*(N)); do
- # Ignore errors ...
- source "$file" 2>/dev/null
- done
-done
-unset dir
# byebye.zlogout -- Say goodbye to interactive users
[[ -o interactive ]] || return
+[[ -n "$AXZSH_PLUGIN_CHECK" ]] || return 92
# Clear the console if it is a local terminal
case `tty` in
# AX-ZSH: Alex' Modular ZSH Configuration
# cheat: Setup https://cht.sh
+if (( $+commands[fzf] )); then
+ # See <https://twitter.com/igor_chubin/status/1343294742315020293>
+ function c() {
+ url="https://cht.sh"
+ term=$(curl -ks "$url/:list" | IFS=+ fzf --preview "curl -ks '$url/{}'" -q "$*") \
+ && curl -ks "$url/${term}" | ${PAGER:-less}
+ }
+fi
+
# Don't overwrite a real "cheat" command!
(( $+commands[cheat] )) && return
# AX-ZSH: Alex' Modular ZSH Configuration
# history.zshrc: Setup ZSH history
-if [[ -z "$HISTFILE" ]]; then
- # Save history file in cache directory, if not already present
- # in $ZDOTDIR/$HOME:
- [ -r "${ZDOTDIR:-$HOME}/.zsh_history" ] \
- && HISTFILE="${ZDOTDIR:-$HOME}/.zsh_history" \
- || HISTFILE="$ZSH_CACHE_DIR/history"
-fi
+function clear_history {
+ local HISTSIZE=0
+ cat /dev/null >"$HISTFILE"
+ fc -R
+}
+
+[[ -n "$HISTFILE" ]] || HISTFILE="${ZDOTDIR:-$HOME}/.zsh_history"
HISTSIZE=10000
SAVEHIST=10000
# Make sure that "less(1)" is installed
(( $+commands[less] )) || return
+export PAGER="$commands[less]"
export LESS="-FmRX"
# Support colors in less
elif (( $+commands[lesspipe.sh] )); then
# Silence lesspipe(1), see <https://github.com/wofr06/lesspipe/issues/21>
export LESSQUIET=1
- eval "$(lesspipe.sh)"
+ eval "$(lesspipe.sh 2>/dev/null)"
fi
ssh-add
}
-_ax_ssh_prompt() {
+_axzsh_ssh_prompt() {
[[ -n "$SSH_CLIENT" ]] || return 1
return 0
}
-ax_logname_prompt_functions=($ax_logname_prompt_functions _ax_ssh_prompt)
-ax_hostname_prompt_functions=($ax_hostname_prompt_functions _ax_ssh_prompt)
+axzsh_logname_prompt_functions=($axzsh_logname_prompt_functions _axzsh_ssh_prompt)
+axzsh_hostname_prompt_functions=($axzsh_hostname_prompt_functions _axzsh_ssh_prompt)
# Validate SSH_AUTH_SOCK: Inside of screen(1) sessions for example, the socket
# file becomes invalid when the session has been disconnected.
# Save SSH environment when available:
if [[ -n "$SSH_AUTH_SOCK" && -d "$XDG_RUNTIME_DIR" ]]; then
- # Save current environment when no state exists or is invalid.
+ # Save current environment when no state exists or state file is invalid.
if [[ -r "$XDG_RUNTIME_DIR/ssh-env.sh" ]]; then
+ # Check existing state file ...
(
source "$XDG_RUNTIME_DIR/ssh-env.sh"
if [[ -z "$SSH_AUTH_SOCK" || ! -r "$SSH_AUTH_SOCK" ]]; then
# std_aliases: Setup standard aliases
alias ll="ls -hl"
-alias l="ll -a"
+alias l="ls -ahl"
+alias la="ls -Ahl"
+alias lx="ls -A"
-alias lasth='last | head -n "$((LINES-1))"'
-alias lastf='last | grep -v "^$LOGNAME"'
+alias lasth='last -aw | head -n "$((LINES-1))"'
+alias lastf='last -aw | grep -v "^$LOGNAME"'
alias d='dirs -v | head -10'
alias 1='cd ~1 && pwd'
alias 7='cd ~7 && pwd'
alias 8='cd ~8 && pwd'
alias 9='cd ~9 && pwd'
+alias -- -='cd -'
+
+alias md='mkdir -p'
+alias rd=rmdir
+
+# Global aliases
+
+alias -g C="| cut -d' '"
+alias -g G="| grep -i"
+alias -g H="| head"
+alias -g L="| less"
+alias -g LL="2>&1 | less"
+alias -g NUL=">/dev/null 2>&1"
+alias -g T="| tail"
+alias -g WL="| wc -l"
+alias -g X="| xargs"
+
+# Suffix aliases
+
+alias -s {c,cfg,conf,css,h,html,ini,json,md,me,rc,txt,yml,yaml}="$EDITOR"
export CLICOLOR=${CLICOLOR:-1}
export MANWIDTH=${MANWIDTH:-80}
-export REPORTTIME=${REPORTTIME:-5}
+
+if [[ "$TERM_PROGRAM" != "WarpTerminal" ]]; then
+ export REPORTTIME=${REPORTTIME:-5}
+fi
# AX-ZSH: Alex' Modular ZSH Configuration
# std_functions: Setup standard ("common") functions
+function open_command() {
+ case $OSTYPE in
+ darwin*)
+ open "$@" || return 1
+ ;;
+ cygwin*)
+ cygstart "$@" || return 1
+ ;;
+ linux*)
+ if [[ -n "$DISPLAY" ]]; then
+ # X11
+ nohup xdg-open "$@" &>/dev/null || return 1
+ else
+ xdg-open "$@" || return 1
+ fi
+ ;;
+ *)
+ return 2
+ esac
+ return 0
+}
+
function take() {
- mkdir -p "$@" && cd "${@:$#}"
+ if [[ $# -eq 0 ]]; then
+ cd "$(mktemp -d)"
+ pwd
+ else
+ mkdir -p "$@" && cd "${@:$#}"
+ fi
+}
+
+function untake() {
+ pwd="${PWD}/"
+ subdir="${pwd##$TMPDIR}"
+ if [[ "${PWD%tmp.*}" = "${TMPDIR}" && -n "$subdir" ]]; then
+ tmp_d="${TMPDIR}${subdir%%/*}"
+ echo "$tmp_d"
+ cd
+ rm -fr "$@" "${tmp_d}"
+ else
+ echo 'Sorry, not a temporarily taken directory!' >&2
+ return 1
+ fi
}
function zsh_stats() {
#!/bin/sh
#
# AX-ZSH: Alex' Modular ZSH Configuration
-# Copyright (c) 2015 Alexander Barton <alex@barton.de>
+# Copyright (c) 2015-2022 Alexander Barton <alex@barton.de>
#
# Include "ax-common.sh":
umask 027
-[ -n "$AXZSH" ] || AXZSH="$HOME/.axzsh"
+[ -n "$AXZSH" ] || AXZSH="${ZDOTDIR:-$HOME}/.axzsh"
export AXZSH
S=$(dirname "$0")
ax_msg - "Linking ZSH startup files ..."
-for f in ~/.zlogin ~/.zlogout ~/.zprofile ~/.zshrc; do
+for f in \
+ ${ZDOTDIR:-$HOME}/.zlogin \
+ ${ZDOTDIR:-$HOME}/.zlogout \
+ ${ZDOTDIR:-$HOME}/.zprofile \
+ ${ZDOTDIR:-$HOME}/.zshrc \
+; do
safe_rm "$f" || abort
ln -sv "$AXZSH/ax.zsh" "$f" || abort
done
zsh "$AXZSH/bin/axzshctl" reset-plugins || abort
else
ax_msg 1 "Oops, \"zsh\" not found!?"
+ exit 1
fi
else
ax_msg - "Plugin directory \"$AXZSH/active_plugins\" already exists. Ok."
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# 00-newline.ax-io: Print an empty line ...
+
+# Don't run this plugin on "check-plugins"!
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
+
+# Don't output anything ~/.hushlogin exists ...
+[[ -r ~/.hushlogin ]] && return 0
+
+echo
--- /dev/null
+## 00-newline
+
+This is a somewhat "silly" plugin, which is run at the very beginning of the
+initialization sequence and just prints a newline character.
+
+This can be handy when your terminal emulator or "login tools" print some
+messages, but you want the ouput of your plugins and the first shell prompt
+clearly separated.
--- /dev/null
+## autojump
+Initialize "autojump", "a cd command that learns", see
+https://github.com/wting/autojump.
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# autojump.zshrc: Initialize "autojump"
+
+for script (
+ "$HOMEBREW_PREFIX/etc/profile.d/autojump.sh"
+ "/usr/local/etc/profile.d/autojump.sh"
+ "/usr/share/autojump/autojump.zsh"
+); do
+ if [[ -r "$script" ]]; then
+ source "$script"
+ unset script
+ return 0
+ fi
+done
+unset script
+return 1
--- /dev/null
+## bat
+
+Find the bat(1) tool and create an alias to "bat" when installed with an other
+name (on Debian, it is installed as "batcat", for example).
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# trash.zshrc: Setup trash(1)
+
+# Make sure that "bat(1)" is installed
+(( $+commands[bat] )) && return 0
+
+if (( $+commands[batcat] )); then
+ alias bat='batcat'
+ return 0
+fi
+
+return 1
--- /dev/null
+## browser_select
+
+Search for the "best" WWW browser and setup environment (`$BROWSER`) accordingly.
+
+The plugin looks for the following WWW browsers and stops at the first one it finds:
+
+- open (on non-Linux platforms)
+- firefox (when DISPLAY is set)
+- chrome (when DISPLAY is set)
+- elinks
+- w3m
+- links2
+- links
+- lynx
+
+### Environment
+
+- `$BROWSER`: Command (including parameters) to run a WWW browser.
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# browser_select.zprofile: Setup $BROWSER for the "best" available WWW browser
+
+# Don't run this plugin on "check-plugins"!
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
+
+if [[ -z "$BROWSER" ]]; then
+ if [[ "$OSTYPE" != "linux-gnu" ]]; then
+ # Check for open(1) on Non-Linux systems. On (Debian-) Linux, the open(1)
+ # command would recursively call $BROWSER (=itself) ...
+ open_browsers="open"
+ fi
+ if [[ -n "$DISPLAY" ]]; then
+ # X11 available, consider X11-based browsers, too!
+ x11_browsers="firefox chrome"
+ fi
+
+ # Note: We can't use xdg-open(1) here, as xdg-open itself tries to use
+ # $BROWSER, and this would result in an endless loop!
+ for browser (
+ $open_browsers
+ $x11_browsers
+ elinks w3m links2 links lynx
+ ); do
+ if [[ -n "$commands[$browser]" ]]; then
+ BROWSER="$commands[$browser]"
+ break
+ fi
+ done
+ unset browser open_browser x11_browsers
+fi
+
+[[ -n "$BROWSER" ]] && export BROWSER
--- /dev/null
+## calendar
+
+Show calendar(1) entries for the current day, but not more often than once
+every hour.
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# calendar.ax-io: Show calendar(1) entries for the current day.
+
+# Make sure that "calendar(1)" is installed.
+(( $+commands[calendar] )) || return 1
+
+# Don't run this plugin on "check-plugins", but test if it would work!
+# It fails when no calendar files are available, for example, on macOS ...
+if [[ -n "$AXZSH_PLUGIN_CHECK" ]]; then
+ calendar >/dev/null 2>&1 || return 1
+ return 0
+fi
+
+# Don't show any info when ~/.hushlogin exists ...
+[[ -r ~/.hushlogin ]] && return 0
+
+# Check if calendar(1) infos have been shown during last 60 minutes, and if so,
+# don't show them now but return.
+[[ -z `find "$XDG_CACHE_HOME/axzsh_last_calendar" -mmin -60 2>/dev/null` ]] || return 0
+
+tmpfile=$(mktemp "$TMPDIR/calendar.XXXXXX") || return 1
+
+calendar -A0 >"$tmpfile"
+if [[ -s "$tmpfile" ]]; then
+ cat "$tmpfile"; echo
+fi
+rm -f "$tmpfile"
+
+# Wtite "stamp" file.
+[[ -w ~/ ]] && touch "$XDG_CACHE_HOME/axzsh_last_calendar"
# AX-ZSH: Alex' Modular ZSH Configuration
# editor_select.zprofile: Setup $EDITOR for the "best" available editor
+if [[ -n "$EDITOR" && ! -x "$EDITOR" && -z "$commands[$EDITOR]" ]]; then
+ # Oops, current $EDITOR seems to be invalid! Start over!
+ unset EDITOR
+fi
+
+if [[ -z "$EDITOR" ]]; then
+ # Check user preferences first!
+ if [[ -r ~/.selected_editor ]]; then
+ . ~/.selected_editor
+ if [[ -x "$SELECTED_EDITOR" || -n "$commands[$SELECTED_EDITOR]" ]]; then
+ EDITOR="$SELECTED_EDITOR"
+ fi
+ unset SELECTED_EDITOR
+ fi
+fi
+
if [[ -z "$EDITOR" ]]; then
+ # Auto-detect a "good" editor ...
if [[ -n "$DISPLAY" ]]; then
# X11 available, consider X11-based editors, too!
- x11_editors="gvim"
+ x11_editors="mousepad gvim vim.motif"
fi
for editor (
+ sensible-editor editor
code atom mate subl mvim
$x11_editors
- vim nano joe vi
+ vim.nox vim.basic micro joe mcedit nano vim vim.tiny nvi vi
); do
- if [ -n "$commands[$editor]" ]; then
+ if [[ -n "$commands[$editor]" ]]; then
EDITOR="$commands[$editor]"
break
fi
"code"|"atom"|"mate"|"subl")
EDITOR="$EDITOR --wait"
;;
- "mvim"|"gvim")
+ "mvim"|"gvim"|"vim.motif")
EDITOR="$EDITOR --nofork"
;;
esac
-if [[ -n "$EDITOR" ]]; then
- export EDITOR
- alias zshenv="$EDITOR ~/.zshenv"
-fi
+[[ -n "$EDITOR" ]] && export EDITOR
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# editor_select.zshrc: Setup $EDITOR for the "best" available editor
+
+# Don't run this plugin on "check-plugins"!
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
+
+[[ -n "$EDITOR" ]] && alias zshenv="$EDITOR ~/.zshenv"
# Test for Debian-specific keybinding location ...
if [[ -r /usr/share/doc/fzf/examples/key-bindings.zsh ]]; then
- source /usr/share/zsh/vendor-completions/_fzf
+ if [[ -r /usr/share/doc/fzf/examples/completion.zsh ]]; then
+ source /usr/share/doc/fzf/examples/completion.zsh
+ elif [[ -r /usr/share/zsh/vendor-completions/_fzf ]]; then
+ source /usr/share/zsh/vendor-completions/_fzf
+ fi
source /usr/share/doc/fzf/examples/key-bindings.zsh
return 0
fi
# Search for and read in FZF ZSH integration files
for dir (
+ "$HOMEBREW_PREFIX"/opt/fzf/shell
/usr/local/lib/fzf/shell
/usr/local/opt/fzf/shell
/usr/local/share/examples/fzf/shell
/opt/fzf/shell
+ /usr/share/fzf/shell
); do
[[ -d "$dir" ]] || continue
- source "$dir/completion.zsh"
+ [[ -r "$dir/completion.zsh" ]] && source "$dir/completion.zsh"
source "$dir/key-bindings.zsh"
return 0
done
# OhMyZsh compatibility functions
alias parse_git_dirty=git_parse_dirty
-ax_vcs_prompt_functions=($ax_vcs_prompt_functions git_prompt)
+axzsh_vcs_prompt_functions=($axzsh_vcs_prompt_functions git_prompt)
-alias ga="git add"
-alias gc="git commit"
-alias gd="git diff --patch-with-stat"
-alias gdc="git diff --patch-with-stat --cached"
-alias gst="git status --short --branch --untracked"
alias fix="git diff --name-only | uniq | xargs $EDITOR"
+alias g="git"
+alias ga="git add"
+alias gapa="git add --patch"
+alias gc="git commit --verbose"
+alias gc!="git commit --verbose --amend"
+alias gca="git commit --verbose --all"
+alias gcam="git commit --verbose --all --message"
+alias gcmsg="git commit --verbose --message"
+alias gcn="git commit --verbose --no-edit"
+alias gcn!="git commit --verbose --no-edit --amend"
+alias gco="git checkout"
+alias gd="git diff"
+alias gdca="git diff --cached"
+alias gdcw="git diff --cached --word-diff"
+alias gdw="git diff --word-diff"
+alias gf="git fetch"
+alias gfa="git fetch --all --prune"
+alias gfo="git fetch origin"
+alias gl="git pull"
+alias glo="git log --oneline --decorate"
+alias gloo="git log --oneline --decorate ORIG_HEAD.."
+alias gp="git push"
+alias gr="git remote"
+alias grb="git rebase"
+alias grbi="git rebase --interactive"
+alias gsb="git status --short --branch"
+alias gsh="git show"
+alias gss="git status --short"
+alias gst="git status"
+alias gsta="git stash push"
+alias gstl="git stash list"
+alias gstp="git stash pop"
(( $+commands[gpg] )) || return 1
fi
-export GPG_TTY=$(tty)
+export GPG_TTY=$TTY
if (( $+commands[gpg-connect-agent] )); then
# Try to start/connect the agent ...
# Make sure that "googler(1)" are installed
(( $+commands[googler] )) || return
-alias g="googler"
+alias g0="googler --show-browser-logs -n $((LINES/6))"
Setup "Homebrew" ("The missing package manager for OS X", http://brew.sh):
- Enable ZSH completions installed by Homebrew formulae.
+- Install a `brew` wrapper function.
+
+This wrapper function for the `brew`(1) command does the following:
+
+- Detect the location of the "real" brew(1) command.
+- Change user and group when the Homebrew installation is owned by a different
+ user (to preserve sane file permissions).
+- Set a relaxed umask(1) so that other users can use software installed by
+ Homebrew.
+- Call the "real" `brew`(1) command.
# AX-ZSH: Alex' Modular ZSH Configuration
# homebrew.zprofile -- Setup Homebrew Package Manager
-# Make sure that "brew(1)" is installed
-(( $+commands[brew] )) || return 1
+# Look for the "brew(1) command ...
+for brew_cmd (
+ /home/linuxbrew/.linuxbrew/bin/brew
+ /opt/homebrew/bin/brew
+ /usr/local/bin/brew
+); do
+ [[ -x "$brew_cmd" ]] && break
+done
+if [[ ! -x "$brew_cmd" ]]; then
+ unset brew_cmd
+ return 1
+fi
-[[ -d "/usr/local/share/zsh-completions" ]] \
- && axzsh_fpath+=(/usr/local/share/zsh-completions)
+eval "$("$brew_cmd" shellenv)"
+
+for dir (
+ "$HOMEBREW_PREFIX/share/zsh-completions"
+ "$HOMEBREW_PREFIX/share/zsh/site-functions"
+); do
+ [[ -d "$dir" ]] && axzsh_fpath+=("$dir")
+done
+unset dir brew_cmd
+
+# Set some defaults, if not set already.
+[[ -z "$HOMEBREW_AUTO_UPDATE_SECS" ]] && HOMEBREW_AUTO_UPDATE_SECS=600
return 0
# Check if reminders have been shown during last 60 minutes, and if so,
# don't show them now but return.
-[[ -z `find ~/.last_reminder -mmin -60 2>/dev/null` ]] || return 0
+[[ -z `find "$XDG_CACHE_HOME/axzsh_last_reminder" -mmin -60 2>/dev/null` ]] || return 0
-tmpfile=$(mktemp ${TMPDIR:-/tmp}/icalbuddy.XXXXXX) || return 1
+tmpfile=$(mktemp "$TMPDIR/icalbuddy.XXXXXX") || return 1
if [[ "$LANG" =~ "\.UTF" ]]; then
bul="•"; bul_imp="!"; sep="»"
tasksDueBefore:today 2>/dev/null >>"$tmpfile"
icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
-nc -npn -iep "title,datetime" \
- eventsToday+1 2>/dev/null >>"$tmpfile"
+ eventsToday+1 2>/dev/null >>"$tmpfile"
if [[ -s "$tmpfile" ]]; then
- echo; cat "$tmpfile"; echo
+ cat "$tmpfile"; echo
fi
rm -f "$tmpfile"
unset bul bul_imp sep tmpfile
# Wtite "stamp" file.
-[[ -w ~/ ]] && touch ~/.last_reminder
+[[ -w ~/ ]] && touch "$XDG_CACHE_HOME/axzsh_last_reminder"
[[ -z "$ITERM_SHELL_INTEGRATION_INSTALLED" ]] || return 91
[[ "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}$TERM" =~ "^screen" ]] && return 91
+# Add iTerm2 commands to PATH, when available.
+[[ -d ~/.iterm2 ]] && path+=(~/.iterm2)
+
# Try to source user-local shell integration installed by iTerm2 itself,
# and only fall back to the implementation here when not found.
[[ -e "$HOME/.iterm2_shell_integration.zsh" ]] && source "$HOME/.iterm2_shell_integration.zsh"
+
+# ax-zsh specific iTerm2 functions
+iterm2_clear_captured_output() {
+ printf "\e]1337;ClearCapturedOutput\e\\"
+}
+
[[ -z "$ITERM_SHELL_INTEGRATION_INSTALLED" ]] || return 0
ITERM_SHELL_INTEGRATION_INSTALLED="Yes"
ITERM2_SHOULD_DECORATE_PROMPT="1"
+if [[ -n "$TMUX" ]]; then
+ # Pass escape sequences through in tmux(1), see
+ # <https://gist.github.com/antifuchs/c8eca4bcb9d09a7bbbcd>.
+ TMUX_PREFIX='\ePtmux;\e'
+ TMUX_POSTFIX='\e\\'
+else
+ unset TMUX_PREFIX TMUX_POSTFIX
+fi
+
# Indicates start of command output. Runs just before command executes.
iterm2_before_cmd_executes() {
- printf "\033]133;C;\007"
+ printf "${TMUX_PREFIX}\033]133;C;\007${TMUX_POSTFIX}"
}
iterm2_set_user_var() {
- printf "\033]1337;SetUserVar=%s=%s\007" "$1" $(printf "%s" "$2" | base64 | tr -d '\n')
+ printf "${TMUX_PREFIX}\033]1337;SetUserVar=%s=%s\007${TMUX_POSTFIX}" "$1" $(printf "%s" "$2" | base64 | tr -d '\n')
}
# Users can write their own version of this method. It should call
# e.g., iterm2_set_user_var currentDirectory $PWD
# Accessible in iTerm2 (in a badge now, elsewhere in the future) as
# \(user.currentDirectory).
-whence -v iterm2_print_user_vars > /dev/null 2>&1
-if [ $? -ne 0 ]; then
+if ! whence iterm2_print_user_vars >/dev/null; then
iterm2_print_user_vars() {
:
}
fi
iterm2_print_state_data() {
- printf "\033]1337;RemoteHost=%s@%s\007" "$USER" "$iterm2_hostname"
- printf "\033]1337;CurrentDir=%s\007" "$PWD"
+ printf "${TMUX_PREFIX}\033]1337;RemoteHost=%s@%s\007${TMUX_POSTFIX}" "$USER" "$HOST"
+ printf "${TMUX_PREFIX}\033]1337;CurrentDir=%s\007${TMUX_POSTFIX}" "$PWD"
iterm2_print_user_vars
}
# Report return code of command; runs after command finishes but before prompt
iterm2_after_cmd_executes() {
- printf "\033]133;D;%s\007" "$STATUS"
+ printf "${TMUX_PREFIX}\033]133;D;%s\007${TMUX_POSTFIX}" "$STATUS"
iterm2_print_state_data
}
# Mark start of prompt
iterm2_prompt_mark() {
- printf "\033]133;A\007"
+ printf "${TMUX_PREFIX}\033]133;A\007${TMUX_POSTFIX}"
}
# Mark end of prompt
iterm2_prompt_end() {
- printf "\033]133;B\007"
+ printf "${TMUX_PREFIX}\033]133;B\007${TMUX_POSTFIX}"
}
# There are three possible paths in life.
ITERM2_SHOULD_DECORATE_PROMPT=""
# Add our escape sequences just before the prompt is shown.
- # Use ITERM2_SQUELCH_MARK for people who can't mdoify PS1 directly, like powerlevel9k users.
- # This is gross but I had a heck of a time writing a correct if statetment for zsh 5.0.2.
+ # Use ITERM2_SQUELCH_MARK for people who can't modify PS1 directly, like powerlevel9k users.
+ # This is gross but I had a heck of a time writing a correct if statement for zsh 5.0.2.
local PREFIX=""
if [[ $PS1 == *"$(iterm2_prompt_mark)"* ]]; then
PREFIX=""
iterm2_precmd() {
local STATUS="$?"
- if [ -z "${ITERM2_SHOULD_DECORATE_PROMPT-}" ]; then
+ if [[ -z "${ITERM2_SHOULD_DECORATE_PROMPT-}" ]]; then
# You pressed ^C while entering a command (iterm2_preexec did not run)
iterm2_before_cmd_executes
fi
iterm2_after_cmd_executes "$STATUS"
- if [ -n "$ITERM2_SHOULD_DECORATE_PROMPT" ]; then
+ if [[ -n "$ITERM2_SHOULD_DECORATE_PROMPT" ]]; then
iterm2_decorate_prompt
fi
}
iterm2_before_cmd_executes
}
-# If hostname -f is slow on your system, set iterm2_hostname prior to sourcing this script.
-[[ -z "$iterm2_hostname" ]] && iterm2_hostname=`hostname -f`
-
precmd_functions+=(iterm2_precmd)
preexec_functions+=(iterm2_preexec)
iterm2_print_state_data
-printf "\033]1337;ShellIntegrationVersion=11;shell=zsh\007"
+printf "${TMUX_PREFIX}\033]1337;ShellIntegrationVersion=12;shell=zsh\007${TMUX_POSTFIX}"
# Setup iTerm2 command aliases
for cmd (~/.iterm2/*(N)); do
--- /dev/null
+## lsd
+
+Setup LSD (LSDeluxe), the next gen ls command:
+<https://github.com/Peltoche/lsd/>
+
+### Prerequisites
+
+- `lsd`(1)
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# lsd.zshrc: Setup LSD (LSDeluxe), the next gen ls command.
+
+# Make sure that "lsd(1)" is installed
+(( $+commands[lsd] )) || return 1
+
+alias ls='lsd'
--- /dev/null
+## neofetch
+
+Show fastfetch(1) or neofetch(1) system information, but not more often than
+once every hour. If both tools are installed, prefer fastfetch(1).
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# neofetch.ax-io: Show fastfetch(1) [preferred] or neofetch(1) system information.
+
+# Make sure that fastfetch(1) or neofetch(1) is installed.
+(( $+commands[fastfetch] )) || (( $+commands[neofetch] )) || return 1
+
+# Don't run this plugin on "check-plugins"!
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 0
+
+# Don't show any info when ~/.hushlogin exists ...
+[[ -r ~/.hushlogin ]] && return 0
+
+# Check if neofetch(1) infos have been shown during last 60 minutes, and if so,
+# don't show them now but return.
+[[ -z $(find "$XDG_CACHE_HOME/axzsh_last_neofetch" -mmin -60 2>/dev/null) ]] || return 0
+
+if (( $+commands[fastfetch] )); then
+ fastfetch
+elif (( $+commands[neofetch] )); then
+ neofetch
+else
+ return 0
+fi
+
+# Wtite "stamp" file.
+[[ -w ~/ ]] && touch "$XDG_CACHE_HOME/axzsh_last_neofetch"
# Check if reminders have been shown during last 60 minutes, and if so,
# don't show them now but return.
-[[ -z `find ~/.last_reminder -mmin -60 2>/dev/null` ]] || return 0
+[[ -z `find "$XDG_CACHE_HOME/axzsh_last_reminder" -mmin -60 2>/dev/null` ]] || return 0
# Show reminders now.
remind -h -g -t5 ~/.remind && echo
# Wtite "stamp" file.
-[[ -w ~/ ]] && touch ~/.last_reminder
+[[ -w ~/ ]] && touch "$XDG_CACHE_HOME/axzsh_last_reminder"
--- /dev/null
+## websearch
+
+Setup some functions and aliases to open various search engines (Google, Ecosia,
+DuckDuckGo, ...) from the command line.
+
+### Functions
+
+- `duckduckgo`: Open DuckDuckGo for the given search terms.
+- `ecosia`: Open Ecosia for the given search terms.
+- `google`: Open Google for the given search terms.
+
+### Aliases
+
+- `ddg`: `duckduckgo`
+- `eco`: `ecosia`
+- `g0`: `google`
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# google.zshrc: Setup functions for using Google in the command line
+
+# This is an optional plugin.
+[[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
+
+function duckduckgo {
+ url="https://duckduckgo.com/?q=$@"
+ open_command "$url" || echo "DuckDuckGo: <$url>"
+}
+alias ddg='duckduckgo'
+
+function ecosia {
+ url="https://www.ecosia.org/search?q=$@"
+ open_command "$url" || echo "Ecosia: <$url>"
+}
+alias eco='ecosia'
+
+function google {
+ url="https://www.google.de/search?q=$@"
+ open_command "$url" || echo "Google: <$url>"
+}
+alias g0='google'
ZSH_THEME_PROMPT_SUFFIX="%b%{$reset_color%}"
ZSH_THEME_PROMPT_SUFFIX_SPACING=" "
-ax_logname_prompt_functions=($ax_logname_prompt_functions ax_logname_prompt_root)
-ax_hostname_prompt_functions=($ax_hostname_prompt_functions ax_hostname_prompt_root)
+axzsh_logname_prompt_functions=($axzsh_logname_prompt_functions axzsh_logname_prompt_root)
+axzsh_hostname_prompt_functions=($axzsh_hostname_prompt_functions axzsh_hostname_prompt_root)
# The primary prompt string, printed before a command is read.
-PS1="$(ax_logname_prompt_yn)$(ax_hostname_prompt_yn)%B%2~%b"'$(ax_vcs_prompt)'"$(ax_prompt)"
+PS1="$(axzsh_logname_prompt_yn)$(axzsh_hostname_prompt_yn)%B%2~%b"'$(axzsh_vcs_prompt)'"$(axzsh_prompt)"
# Primary prompt on the right-hand side.
axzsh_is_utf_terminal \
RPS1="%(?..%{$fg_no_bold[red]%}<%?>%{$reset_color%})"
fi
+axzsh_logname_prompt_functions=($axzsh_logname_prompt_functions axzsh_logname_prompt_root)
+axzsh_hostname_prompt_functions=($axzsh_hostname_prompt_functions axzsh_hostname_prompt_root)
+
# The primary prompt string, printed before a command is read.
-PS1="${system_emoji}${emoji_spacing} $(ax_logname_prompt_yn)$(ax_hostname_prompt_yn)%B%2~%b"'$(ax_vcs_prompt)'"$(ax_prompt)"
+PS1="${system_emoji}${emoji_spacing} $(axzsh_logname_prompt_yn)$(axzsh_hostname_prompt_yn)%B%2~%b"'$(axzsh_vcs_prompt)'"$(axzsh_prompt)"
# Default execution trace prompt.
PS4="$fg_no_bold[yellow]->$reset_color "
ZSH_THEME_PROMPT_SUFFIX_SPACING=" "
-PS1="%{$fg_bold[green]%}%n@%m%{$reset_color%}:%{$fg_bold[blue]%}%~%{$reset_color%}"'$(ax_vcs_prompt)'"$(ax_prompt)"
+PS1="%{$fg_bold[green]%}%n@%m%{$reset_color%}:%{$fg_bold[blue]%}%~%{$reset_color%}"'$(axzsh_vcs_prompt)'"$(axzsh_prompt)"
# ohmyzsh.axzshtheme: OhMyZSH "robbyrussell" theme
ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)"
-PS1='${ret_status} %{$fg[cyan]%}%c%b $(ax_vcs_prompt)%b '
+PS1='${ret_status} %{$fg[cyan]%}%c%b $(axzsh_vcs_prompt)%b '
ZSH_THEME_VCS_PROMPT_PREFIX_SPACING="%{$fg_bold[blue]%}vcs:("
ZSH_THEME_VCS_PROMPT_PREFIX="%{$fg[red]%}"
--- /dev/null
+# AX-ZSH: Alex' Modular ZSH Configuration
+# starship.axzshtheme: Enable extnerl "Starship" Theme
+# see <https://starship.rs/>
+
+if (( $+commands[starship] )); then
+ eval "$(starship init zsh)"
+else
+ echo "Oops, starship(1) command not found, can't enable Starship prompt!" >&2
+fi