diff options
author | Martin Fischer <martin@push-f.com> | 2024-11-29 08:54:33 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2024-12-11 08:37:52 +0100 |
commit | b3e73f8b5d94405e2f0fce52e8d219e37e54791d (patch) | |
tree | 7d1afa60772c8588a421bf9cd28a159d239222fe | |
parent | 563c3eaa9c00cc8acc9835e3ec456793fe49e0ec (diff) |
add zsh
-rwxr-xr-x | link-user | 2 | ||||
-rw-r--r-- | nixos/parts/basics.nix | 20 | ||||
-rw-r--r-- | user/zsh/.zshrc | 69 |
3 files changed, 90 insertions, 1 deletions
@@ -1,7 +1,7 @@ #!/usr/bin/env bash # Symlinks the files in user/ into my XDG_CONFIG_HOME. -XDG_CONFIG_HOME=$HOME/.config +set -u cd $(dirname "$0") # change to the directory of the script cd user diff --git a/nixos/parts/basics.nix b/nixos/parts/basics.nix index 197e22e..77bc68d 100644 --- a/nixos/parts/basics.nix +++ b/nixos/parts/basics.nix @@ -4,4 +4,24 @@ environment.systemPackages = with pkgs; [ git ]; + + users.defaultUserShell = pkgs.zsh; + programs.zsh = { + enable = true; + + # Disabling compinit in /etc/zshrc so that we can call + # compinit with a custom zcompdump location in .zshrc. + enableGlobalCompInit = false; + }; + + environment.sessionVariables = + let + config = "$HOME/config/user"; + in + { + # Set environment variables for software that doesn't + # follow the XDG Base Directory specification. + + ZDOTDIR = "${config}/zsh"; + }; } diff --git a/user/zsh/.zshrc b/user/zsh/.zshrc new file mode 100644 index 0000000..624cb33 --- /dev/null +++ b/user/zsh/.zshrc @@ -0,0 +1,69 @@ +# This is my ZSH config file. I'm using ZSH over Bash +# because it has better autocompletion. + +## Key bindings +# vi mode +bindkey -v +# default in Bash +bindkey "^R" history-incremental-search-backward + +## Options +setopt autocd +setopt nomatch + +## Functions +function ls() { + # Hide the mess in the home directory by default. + if [[ $PWD == $HOME ]]; then + command ls "$@" + else + command ls --almost-all "$@" + fi +} + +## Aliases +alias ls='ls --color=auto --group-directories-first' # see also ls function + +## Shell variables +PS1='%F{magenta}' + PS1+='%n' # username +PS1+='%f' +PS1+='@' +PS1+='%m' # hostname +PS1+=' ' +PS1+='%B' + PS1+='%40<..<' # truncate (40 chars, indicate with ..) + PS1+='%~' # current directory + PS1+='%<<' +PS1+='%b' +PS1+=' ' +PS1+='%#' # `#` if the shell runs with privileges else `%` +PS1+=' ' + +HISTSIZE=1000000000 +SAVEHIST=1000000000 + +## Environment variables +export XDG_CACHE_HOME=$HOME/.cache +export XDG_CONFIG_HOME=$HOME/.config + +## Completion +autoload -Uz compinit +[ -d "$XDG_CACHE_HOME"/zsh ] || mkdir -p "$XDG_CACHE_HOME"/zsh +compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-$ZSH_VERSION + +# Terminal emulator specifics +if [ $TERM = foot ]; then + # Enable spawning of new terminal instances in the current working directory + function osc7-pwd() { + emulate -L zsh # also sets localoptions for us + setopt extendedglob + local LC_ALL=C + printf '\e]7;file://%s%s\e\' $HOST ${PWD//(#m)([^@-Za-z&-;_~])/%${(l:2::0:)$(([##16]#MATCH))}} + } + + function chpwd-osc7-pwd() { + (( ZSH_SUBSHELL )) || osc7-pwd + } + add-zsh-hook -Uz chpwd chpwd-osc7-pwd +fi |