From c6ab46f85c090e24ac4dc96699ac5b24f7e2e679 Mon Sep 17 00:00:00 2001 From: hektor Date: Sun, 27 Sep 2026 23:37:01 +0200 Subject: [PATCH] refactor(shell): nixify remaining shell config --- dots/.bash_aliases/all | 57 ------------------- dots/.bashrc.d/prompt | 22 ------- dots/.inputrc | 33 ----------- home/modules/fzf/default.nix | 31 ++++++++++ home/modules/readline/default.nix | 46 +++++++++++++++ home/modules/shell/bash-aliases.nix | 54 ++++++++++++++++++ .../modules/shell/bash-js.bash | 4 -- home/modules/shell/bash.nix | 23 +++----- home/modules/shell/default.nix | 14 ++++- home/modules/shell/prompt.nix | 2 +- home/modules/shell/utils.nix | 18 +----- home/modules/tmux/default.nix | 5 +- modules/audio/default.nix | 5 +- 13 files changed, 155 insertions(+), 159 deletions(-) delete mode 100644 dots/.bash_aliases/all delete mode 100644 dots/.bashrc.d/prompt delete mode 100644 dots/.inputrc create mode 100644 home/modules/fzf/default.nix create mode 100644 home/modules/readline/default.nix create mode 100644 home/modules/shell/bash-aliases.nix rename dots/.bash_aliases/lang-js => home/modules/shell/bash-js.bash (91%) diff --git a/dots/.bash_aliases/all b/dots/.bash_aliases/all deleted file mode 100644 index 7f525ce..0000000 --- a/dots/.bash_aliases/all +++ /dev/null @@ -1,57 +0,0 @@ -# shellcheck shell=bash -# vim: set ft=bash : - -alias ..="cd .." - -alias ls="ls --color=auto" -alias l="ls -1p" -alias ll="ls -lhp" -alias lt="ls -lhtp" -alias la="ls -lhap" -alias lta="ls -lhatp" -alias ldir="ls -dp" # list directories - -alias grep="grep --color=auto" - -alias rm="rm -I --preserve-root" -alias mv="mv -iv" -alias cp="cp -iv" -alias ln="ln -i" -alias mkdir="mkdir -pv" -alias chown="chown --preserve-root" -alias chmod="chmod --preserve-root" -alias chgrp="chgrp --preserve-root" - -alias ip="ip --color" -alias ipa="ip -brief address" -alias ipl="ip -brief link" -alias ipr="ip route" - -alias df="df -kTh" -alias fzfpac="pacman -Slq | fzf -m --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S" -alias path='echo -e ${PATH//:/\\n}' # Pretty print path variables - -# Programs -alias h="history" -alias o="xdg-open" -alias v="nvim" -alias vf="fzf --bind 'enter:become(nvim {})'" -alias g='git' -alias k="kubectl" -alias t='task' -alias tsh='tasksh' -alias z='zathura --fork' -alias f='fzf' -alias fm='pcmanfm &>/dev/null &' -alias mm='micromamba' - -# Languages -alias r5="plt-r5rs --no-prim" -alias hs="ghci" -alias pl="swipl" -alias py="python" -alias r="R" - -alias azerty="setxkbmap be" -alias qwerty="setxkbmap us" -alias cole="setxkbmap us -variant colemak" diff --git a/dots/.bashrc.d/prompt b/dots/.bashrc.d/prompt deleted file mode 100644 index a739826..0000000 --- a/dots/.bashrc.d/prompt +++ /dev/null @@ -1,22 +0,0 @@ -# shellcheck shell=bash -# vim: set ft=bash : - -get_branch_name() { - git symbolic-ref --quiet --short HEAD 2>/dev/null \ - || git rev-parse --short HEAD 2>/dev/null \ - || echo 'some branch' -} -get_git_info() { - git rev-parse --is-inside-work-tree &>/dev/null || return - echo -e "($(get_branch_name))" -} - -if [[ $SSH_CONNECTION ]]; then - PS1='\[\033[01;31m\]\u@\h\[\033[00m\] $(get_git_info)\W❭\[$(tput sgr0)\] ' -else - PS1='\u $(get_git_info)\W❭\[$(tput sgr0)\] ' -fi - -# Ellipsis when deep in directory -export PROMPT_DIRTRIM=2 -export PS1 diff --git a/dots/.inputrc b/dots/.inputrc deleted file mode 100644 index 04cb0c7..0000000 --- a/dots/.inputrc +++ /dev/null @@ -1,33 +0,0 @@ -$include /etc/inputrc - -set editing-mode vi -set keymap vi -set show-mode-in-prompt on -set vi-ins-mode-string "\1\e[1;32m\2■ \1\e[0m\2" -set vi-cmd-mode-string "\1\e[1;31m\2■ \1\e[0m\2" - -set show-all-if-ambiguous on -set show-all-if-unmodified off -set completion-ignore-case on -set completion-map-case on -set completion-display-width 0 -set page-completions off -set completion-query-items 128 -set visible-stats on -set skip-completed-text on -set mark-symlinked-directories on -set colored-completion-prefix on - -$if mode=vi - set keyseq-timeout 200 - set keymap vi-command - "\e[A": history-search-backward - "\e[B": history-search-forward - j: history-search-forward - k: history-search-backward - set keymap vi-insert - "jj": vi-movement-mode - "\e[A": history-search-backward - "\e[B": history-search-forward - "\C-l": clear-screen -$endif diff --git a/home/modules/fzf/default.nix b/home/modules/fzf/default.nix new file mode 100644 index 0000000..684e75b --- /dev/null +++ b/home/modules/fzf/default.nix @@ -0,0 +1,31 @@ +{ + config, + lib, + pkgs, + ... +}: + +{ + options.fzf.enable = lib.mkEnableOption "fzf"; + + config = lib.mkIf config.fzf.enable { + programs.fzf = { + enable = true; + enableBashIntegration = lib.mkDefault true; + defaultCommand = "rg --files"; + defaultOptions = [ + "--pointer='❭'" + "--height 10%" + ]; + fileWidget = { + command = "rg --files"; + options = [ "--preview 'bat {} | head -500'" ]; + }; + }; + + home.packages = with pkgs; [ + ripgrep + bat + ]; + }; +} diff --git a/home/modules/readline/default.nix b/home/modules/readline/default.nix new file mode 100644 index 0000000..5c43420 --- /dev/null +++ b/home/modules/readline/default.nix @@ -0,0 +1,46 @@ +{ lib, config, ... }: + +{ + options.readline.enable = lib.mkEnableOption "readline"; + + config = lib.mkIf config.readline.enable { + programs.readline = { + enable = true; + includeSystemConfig = true; + variables = { + editing-mode = "vi"; + keymap = "vi"; + show-mode-in-prompt = true; + vi-ins-mode-string = ''"\1\e[1;32m\2■ \1\e[0m\2"''; + vi-cmd-mode-string = ''"\1\e[1;31m\2■ \1\e[0m\2"''; + + show-all-if-ambiguous = true; + show-all-if-unmodified = false; + completion-ignore-case = true; + completion-map-case = true; + completion-display-width = 0; + page-completions = false; + completion-query-items = 128; + visible-stats = true; + skip-completed-text = true; + mark-symlinked-directories = true; + colored-completion-prefix = true; + }; + extraConfig = '' + $if mode=vi + set keyseq-timeout 200 + set keymap vi-command + "\e[A": history-search-backward + "\e[B": history-search-forward + j: history-search-forward + k: history-search-backward + set keymap vi-insert + "jj": vi-movement-mode + "\e[A": history-search-backward + "\e[B": history-search-forward + "\C-l": clear-screen + $endif + ''; + }; + }; +} diff --git a/home/modules/shell/bash-aliases.nix b/home/modules/shell/bash-aliases.nix new file mode 100644 index 0000000..0d81941 --- /dev/null +++ b/home/modules/shell/bash-aliases.nix @@ -0,0 +1,54 @@ +{ + ".." = "cd .."; + + ls = "ls --color=auto"; + l = "ls -1p"; + ll = "ls -lhp"; + lt = "ls -lhtp"; + la = "ls -lhap"; + lta = "ls -lhatp"; + ldir = "ls -dp"; # list directories + grep = "grep --color=auto"; + + rm = "rm -I --preserve-root"; + mv = "mv -iv"; + cp = "cp -iv"; + ln = "ln -i"; + mkdir = "mkdir -pv"; + chown = "chown --preserve-root"; + chmod = "chmod --preserve-root"; + chgrp = "chgrp --preserve-root"; + + ip = "ip --color"; + ipa = "ip -brief address"; + ipl = "ip -brief link"; + ipr = "ip route"; + df = "df -kTh"; + fzfpac = "pacman -Slq | fzf -m --preview 'pacman -Si {1}' | xargs -ro sudo pacman -S"; + path = ''echo -e ''${PATH//:/\\n}''; # Pretty print path variables + + # Programs + h = "history"; + o = "xdg-open"; + v = "nvim"; + vf = "fzf --bind 'enter:become(nvim {})'"; + g = "git"; + k = "kubectl"; + t = "task"; + tsh = "tasksh"; + z = "zathura --fork"; + f = "fzf"; + fm = "pcmanfm &>/dev/null &"; + mm = "micromamba"; + + # Languages + r5 = "plt-r5rs --no-prim"; + hs = "ghci"; + pl = "swipl"; + py = "python"; + r = "R"; + + azerty = "setxkbmap be"; + qwerty = "setxkbmap us"; + cole = "setxkbmap us -variant colemak"; +} diff --git a/dots/.bash_aliases/lang-js b/home/modules/shell/bash-js.bash similarity index 91% rename from dots/.bash_aliases/lang-js rename to home/modules/shell/bash-js.bash index cf4117f..d477864 100644 --- a/dots/.bash_aliases/lang-js +++ b/home/modules/shell/bash-js.bash @@ -1,8 +1,4 @@ # shellcheck shell=bash -# vim: set ft=bash : - -alias js="node" -alias ts="ts-node" yarn() { if [[ -f "package-lock.json" ]]; then diff --git a/home/modules/shell/bash.nix b/home/modules/shell/bash.nix index 62ebf2b..4b70641 100644 --- a/home/modules/shell/bash.nix +++ b/home/modules/shell/bash.nix @@ -37,7 +37,12 @@ in programs.bash = { enable = true; enableCompletion = true; - + shellAliases = + lib.optionalAttrs cfg.aliases.all (import ./bash-aliases.nix) + // lib.optionalAttrs cfg.aliases.lang-js { + js = "node"; + ts = "ts-node"; + }; historySize = 999999; historyFileSize = -1; # unlimited historyControl = [ @@ -52,29 +57,15 @@ in "ls" "cd" ]; - initExtra = '' for f in ${homeDirectory}/.bashrc.d/*; do [ -f "$f" ] && source "$f" done - - ${lib.optionalString cfg.aliases.all "source ${homeDirectory}/.bash_aliases/all"} - ${lib.optionalString cfg.aliases.lang-js "source ${homeDirectory}/.bash_aliases/lang-js"} - + ${lib.optionalString cfg.aliases.lang-js (builtins.readFile ./bash-js.bash)} ${cfg.extraInit} ''; }; - home.file = { - ".inputrc".source = dotsPath + "/.inputrc"; - ".bashrc.d/prompt".source = dotsPath + "/.bashrc.d/prompt"; - } - // lib.optionalAttrs cfg.aliases.all { - ".bash_aliases/all".source = dotsPath + "/.bash_aliases/all"; - } - // lib.optionalAttrs cfg.aliases.lang-js { - ".bash_aliases/lang-js".source = dotsPath + "/.bash_aliases/lang-js"; - }; home.sessionPath = lib.optional cfg.addBinToPath "${dotsPath}/.bin"; }; } diff --git a/home/modules/shell/default.nix b/home/modules/shell/default.nix index 0957921..f414b78 100644 --- a/home/modules/shell/default.nix +++ b/home/modules/shell/default.nix @@ -7,13 +7,23 @@ { imports = [ ./bash.nix - ./utils.nix ./prompt.nix + ./utils.nix ]; - options.shell.enable = lib.mkEnableOption "shell"; + options = { + shell.enable = lib.mkEnableOption "shell"; + prompt.enable = lib.mkEnableOption "shell prompt" // { + default = config.shell.enable; + }; + utils.enable = lib.mkEnableOption "shell utilities" // { + default = config.shell.enable; + }; + }; config = lib.mkIf config.shell.enable { + fzf.enable = lib.mkDefault true; + readline.enable = lib.mkDefault true; tmux.enable = lib.mkDefault true; }; } diff --git a/home/modules/shell/prompt.nix b/home/modules/shell/prompt.nix index b099736..ffe7c9a 100644 --- a/home/modules/shell/prompt.nix +++ b/home/modules/shell/prompt.nix @@ -5,7 +5,7 @@ }: { - config = lib.mkIf config.shell.enable { + config = lib.mkIf config.prompt.enable { programs.starship = { enable = true; settings = { diff --git a/home/modules/shell/utils.nix b/home/modules/shell/utils.nix index 30b604b..8525109 100644 --- a/home/modules/shell/utils.nix +++ b/home/modules/shell/utils.nix @@ -1,26 +1,12 @@ { - config, lib, + config, pkgs, ... }: { - config = lib.mkIf config.shell.enable { - programs.fzf = { - enable = true; - enableBashIntegration = lib.mkDefault true; - defaultCommand = "rg --files"; - defaultOptions = [ - "--pointer='❭'" - "--height 10%" - ]; - fileWidget = { - command = "rg --files"; - options = [ "--preview 'bat {} | head -500'" ]; - }; - }; - + config = lib.mkIf config.utils.enable { home.packages = with pkgs; [ ripgrep bat diff --git a/home/modules/tmux/default.nix b/home/modules/tmux/default.nix index cba6e82..ddde283 100644 --- a/home/modules/tmux/default.nix +++ b/home/modules/tmux/default.nix @@ -6,13 +6,10 @@ ... }: -let - cfg = config.tmux; -in { options.tmux.enable = lib.mkEnableOption "tmux"; - config = lib.mkIf cfg.enable { + config = lib.mkIf config.tmux.enable { home.packages = with pkgs; [ tmuxp reptyr diff --git a/modules/audio/default.nix b/modules/audio/default.nix index b6f3617..160af45 100644 --- a/modules/audio/default.nix +++ b/modules/audio/default.nix @@ -1,14 +1,11 @@ { lib, config, ... }: -let - cfg = config.audio; -in { imports = [ ./audio-automation.nix ]; options.audio.enable = lib.mkEnableOption "audio"; - config = lib.mkIf cfg.enable { + config = lib.mkIf config.audio.enable { nixpkgs.allowedUnfree = [ "spotify" "spotify-unwrapped"