Skip to content

Instantly share code, notes, and snippets.

@Birdie0
Last active September 15, 2023 13:16
Show Gist options
  • Save Birdie0/c20ae3a92e01c4db348d2f5270255b0b to your computer and use it in GitHub Desktop.
Save Birdie0/c20ae3a92e01c4db348d2f5270255b0b to your computer and use it in GitHub Desktop.
Bash / Zsh / fish config files

bash

# --login/-l for login shell
shopt -q login_shell && echo 'login shell' || echo 'non-login shell'
# -i for interactive shell
[[ $- == *i* ]] && echo 'interactive shell' || echo 'non-interactive shell'
  • login shell
    • --noprofile to disable
    • on startup
      • /etc/profile
        • /etc/bash.bashrc
        • /etc/profile.d/*.sh
      • ~/.bash_profile or ~/.bash_login or ~/.profile
        • ~/.bashrc
    • on exit
      • ~/.bash_logout
  • non-login interactive shell
    • --norc to disable
    • on startup
      • /etc/bash.bashrc
      • ~/.bashrc
  • non-login non-interactive shell
    • doesn't source anything

fish

# --login/-l for login shell
status is-login; and echo 'login shell'; or echo 'non-login shell'
# --interactive/-i for interactive shell
status is-interactive; and echo 'interactive shell'; or echo 'non-interactive shell'
  • fish dir variables

    • $__fish_config_dir = $XDG_CONFIG_HOME/fish = ~/.config/fish
    • $__fish_sysconf_dir = /etc/fish
    • $__fish_user_data_dir = $XDG_DATA_HOME/fish = ~/.local/share/fish
    • $__fish_data_dir = /usr/share/fish
  • fish vendor dirs variables

    • these variables are inherited from $XDG_DATA_DIRS colon-separated path variable (/some/path1:/some/path2) with different suffix paths appended
    • if empty it checks $__fish_data_dir is used as base directory
    • originally used in /usr/share/fish/config.fish file and editing after startup won't effect anything
    • $__fish_vendor_confdirs - list of paths from $XDG_DATA_DIRS with appended /fish/vendor_conf.d appended to each
    • $__fish_vendor_functionsdirs - list of paths from $XDG_DATA_DIRS with appended /fish/vendor_functions.d appended to each
    • $__fish_vendor_completionsdirs - list of paths from $XDG_DATA_DIRS with appended /fish/vendor_completions.d appended to each
  • on startup

    • --no-config/-N skips sourcing all the next files
    • config files
      • /usr/share/fish/config.fish
        • if there are files with indentical basename (/some/path/dir.fish -> dir.fish) only first one will be read
        • $__fish_config_dir/conf.d/*.fish
        • $__fish_sysconf_dir/conf.d/*.fish
        • $__fish_vendor_confdirs/*.fish
      • $__fish_sysconf_dir/config.fish
      • $__fish_config_dir/config.fish
  • lazy load

    • functions and completions are lazily loaded and don't need to be sourced as config files
    • new paths can be added by appending to fish_function_path and fish_complete_path variables with no reload required
    • if there multiple identical functions/completions in the path first found takes precedence
    • functions
      • $__fish_config_dir/functions
      • $__fish_sysconf_dir/functions
      • $__fish_vendor_functionsdirs
      • $__fish_data_dir/functions
    • completions
      • $__fish_config_dir/completions
      • $__fish_sysconf_dir/completions
      • $__fish_vendor_completionsdirs
      • $__fish_data_dir/completions
      • $__fish_user_data_dir/generated_completions - generated by fish_update_completions command

zsh

# --login/-l for login shell
[[ -o login ]] && echo 'login shell' || echo 'non-login shell'
# --interactive/-i for interactive shell
[[ -o interactive ]] && echo 'interactive shell' || echo 'non-interactive shell'
  • $ZDOTDIR = $HOME if unset
  • on startup
    • /etc/zsh/zshenv
      • --no-rcs/-f makes it only file to be sourced
    • $ZDOTDIR/.zshenv
    • login shell
      • /etc/zsh/zprofile
      • $ZDOTDIR/.zprofile
    • interactive shell
      • /etc/zsh/zshrc
      • $ZDOTDIR/.zshrc
    • login shell
      • /etc/zsh/zlogin
      • $ZDOTDIR/.zlogin
  • on exit
    • login shell
      • /etc/zsh/zlogout
      • $ZDOTDIR/.zlogout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment