nix: Integrate more shell files

Also I was thinking of getting rid of bash but... I spent so much time
differentiating which options are for sh/bash/zsh that I don't feel like
losing this data for now.
This commit is contained in:
Geoffrey Frogeye 2023-11-07 21:49:36 +01:00
parent b5c39614c9
commit ab4e33a825
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
4 changed files with 160 additions and 202 deletions

View file

@ -1,83 +1,169 @@
{ pkgs, config, ... }: { pkgs, config, lib, ... }:
{ {
programs = { programs =
home-manager.enable = true; let
bash.enable = true; # Just in case the default shell is not ZSH, so we still have the variables commonRc = ''
zsh = { # Colored ls
enable = true; # TODO Doesn't allow completion
enableAutosuggestions = true; _colored_ls() {
enableCompletion = true; \ls -lh --color=always $@ | awk '
enableSyntaxHighlighting = true; BEGIN {
# syntaxHighlighting.enable = true; # 23.11 syntax FPAT = "([[:space:]]*[^[:space:]]+)";
historySubstringSearch.enable = true; OFS = "";
initExtra = builtins.readFile ./zshrc.sh; }
defaultKeymap = "viins"; {
history = { $1 = "\033[36m" $1 "\033[0m";
size = 100000; $2 = "\033[31m" $2 "\033[0m";
save = 100000; $3 = "\033[32m" $3 "\033[0m";
expireDuplicatesFirst = true; $4 = "\033[32m" $4 "\033[0m";
$5 = "\033[31m" $5 "\033[0m";
$6 = "\033[34m" $6 "\033[0m";
$7 = "\033[34m" $7 "\033[0m";
print
}
'
}
alias ll="_colored_ls"
alias la="_colored_ls -a"
'';
commonSessionVariables = {
TIME_STYLE = "+%Y-%m-%d %H:%M:%S";
# Less colors
LESS = "-R";
LESS_TERMCAP_mb = "$'\E[1;31m'"; # begin blink
LESS_TERMCAP_md = "$'\E[1;36m'"; # begin bold
LESS_TERMCAP_me = "$'\E[0m'"; # reset bold/blink
LESS_TERMCAP_so = "$'\E[01;44;33m'"; # begin reverse video
LESS_TERMCAP_se = "$'\E[0m'"; # reset reverse video
LESS_TERMCAP_us = "$'\E[1;32m'"; # begin underline
LESS_TERMCAP_ue = "$'\E[0m'"; # reset underline
# Fzf
FZF_COMPLETION_OPTS = "${lib.strings.concatStringsSep " " config.programs.fzf.fileWidgetOptions}";
}; };
}; commonShellAliases = {
powerline-go = { cp = "cp -i --reflink=auto";
enable = true; grep = "grep --color=auto";
modules = [ "user" "host" "venv" "cwd" "perms" "git" ]; dd = "dd status=progress";
modulesRight = [ "jobs" "exit" "duration" "load" ]; rm = "rm -v --one-file-system";
settings = { free = "free -m";
colorize-hostname = true; diff = "diff --color=auto";
max-width = 25; dmesg = "dmesg --ctime";
cwd-max-dir-size = 10; wget = "wget --hsts-file ${config.xdg.cacheHome}/wget-hsts";
duration = "$( test -n \"$__TIMER\" && echo $(( $EPOCHREALTIME - $\{__TIMER:-EPOCHREALTIME})) || echo 0 )";
# UPST Implement this properly in home-manager
}; };
extraUpdatePS1 = ''unset __TIMER''; historySize = 100000;
}; historyFile = "${config.xdg.cacheHome}/shell_history";
# neovim = { in
# enable = true; {
# defaultEditor = true; home-manager.enable = true;
# vimAlias = true; bash = {
# viAlias = true; enable = true;
# vimdiffAlias = true; bashrcExtra = lib.strings.concatLines [
# }; commonRc
# FIXME Still want this despite using nixvim ''
gpg = { shopt -s expand_aliases
enable = true; shopt -s histappend
homedir = "${config.xdg.stateHome}/gnupg"; ''
settings = { ];
# Remove fluff sessionVariables = commonSessionVariables;
no-greeting = true; historySize = historySize;
no-emit-version = true; historyFile = historyFile;
no-comments = true; historyFileSize = historySize;
# Output format that I prefer historyControl = [ "erasedups" "ignoredups" "ignorespace" ];
keyid-format = "0xlong"; shellAliases = commonShellAliases;
# Show fingerprints
with-fingerprint = true;
# Make sure to show if key is invalid
# (should be default on most platform,
# but just to be sure)
list-options = "show-uid-validity";
verify-options = "show-uid-validity";
# Stronger algorithm (https://wiki.archlinux.org/title/GnuPG#Different_algorithm)
personal-digest-preferences = "SHA512";
cert-digest-algo = "SHA512";
default-preference-list = "SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed";
personal-cipher-preferences = "TWOFISH CAMELLIA256 AES 3DES";
}; };
publicKeys = [{ zsh = {
source = builtins.fetchurl { enable = true;
url = "https://keys.openpgp.org/vks/v1/by-fingerprint/4FBA930D314A03215E2CDB0A8312C8CAC1BAC289"; enableAutosuggestions = true;
sha256 = "sha256:10y9xqcy1vyk2p8baay14p3vwdnlwynk0fvfbika65hz2z8yw2cm"; enableCompletion = true;
enableSyntaxHighlighting = true;
# syntaxHighlighting.enable = true; # 23.11 syntax
historySubstringSearch.enable = true;
initExtra = lib.strings.concatLines [
commonRc
(builtins.readFile ./zshrc.sh)
];
defaultKeymap = "viins";
history = {
size = historySize;
save = historySize;
path = historyFile;
expireDuplicatesFirst = true;
}; };
trust = "ultimate"; sessionVariables = commonSessionVariables;
}]; shellAliases = commonShellAliases;
};
dircolors = {
enable = true;
enableBashIntegration = true;
enableZshIntegration = true;
# UPST This thing put stuff in .dircolors when it actually doesn't have to
};
powerline-go = {
enable = true;
modules = [ "user" "host" "venv" "cwd" "perms" "git" ];
modulesRight = [ "jobs" "exit" "duration" "load" ];
settings = {
colorize-hostname = true;
max-width = 25;
cwd-max-dir-size = 10;
duration = "$( test -n \"$__TIMER\" && echo $(( $EPOCHREALTIME - $\{__TIMER:-EPOCHREALTIME})) || echo 0 )";
# UPST Implement this properly in home-manager, would allow for bash support
};
extraUpdatePS1 = ''unset __TIMER'';
};
# neovim = {
# enable = true;
# defaultEditor = true;
# vimAlias = true;
# viAlias = true;
# vimdiffAlias = true;
# };
# FIXME Still want this despite using nixvim
gpg = {
enable = true;
homedir = "${config.xdg.stateHome}/gnupg";
settings = {
# Remove fluff
no-greeting = true;
no-emit-version = true;
no-comments = true;
# Output format that I prefer
keyid-format = "0xlong";
# Show fingerprints
with-fingerprint = true;
# Make sure to show if key is invalid
# (should be default on most platform,
# but just to be sure)
list-options = "show-uid-validity";
verify-options = "show-uid-validity";
# Stronger algorithm (https://wiki.archlinux.org/title/GnuPG#Different_algorithm)
personal-digest-preferences = "SHA512";
cert-digest-algo = "SHA512";
default-preference-list = "SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed";
personal-cipher-preferences = "TWOFISH CAMELLIA256 AES 3DES";
};
publicKeys = [{
source = builtins.fetchurl {
url = "https://keys.openpgp.org/vks/v1/by-fingerprint/4FBA930D314A03215E2CDB0A8312C8CAC1BAC289";
sha256 = "sha256:10y9xqcy1vyk2p8baay14p3vwdnlwynk0fvfbika65hz2z8yw2cm";
};
trust = "ultimate";
}];
};
fzf = {
enable = true;
enableZshIntegration = true;
defaultOptions = [ "--height 40%" "--layout=default" ];
fileWidgetOptions = [ "--preview '[[ -d {} ]] && ls -l --color=always {} || [[ \$(file --mime {}) =~ binary ]] && file --brief {} || (highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null | head -500'" ];
};
# TODO highlight or bat
nix-index = {
enable = true;
enableZshIntegration = true;
};
less.enable = true;
}; };
fzf.enable = true;
# TODO highlight or bat
nix-index = {
enable = true;
enableZshIntegration = true;
};
};
home = { home = {
stateVersion = "23.05"; stateVersion = "23.05";
language = { language = {
@ -162,5 +248,6 @@
syncthing syncthing
]; ];
sessionVariables = { };
}; };
} }

View file

@ -1,49 +0,0 @@
#!/usr/bin/env bash
#
# Bash aliases and customizations
#
# Shell options
shopt -s expand_aliases
shopt -s histappend
HISTCONTROL=ignoreboth:erasedups
# Prompt customization
if command -v powerline-go > /dev/null
then
INTERACTIVE_BASHPID_TIMER="${HOME}/.cache/bash_timer_$$"
PS0='$(echo $SECONDS > "$INTERACTIVE_BASHPID_TIMER")'
function _update_ps1() {
local __ERRCODE=$?
local __DURATION=0
if [ -e "$INTERACTIVE_BASHPID_TIMER" ]; then
local __END=$SECONDS
local __START=$(cat "$INTERACTIVE_BASHPID_TIMER")
__DURATION="$(($__END - ${__START:-__END}))"
\rm -f "$INTERACTIVE_BASHPID_TIMER"
fi
echo -en "\033]0; ${USER}@${HOSTNAME} $PWD\007"
# echo -en "… $\r"
eval "$(powerline-go -shell bash -eval -duration $__DURATION -error $__ERRCODE "${POWERLINE_GO_DEFAULT_OPTS[@]}")"
}
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
else
export PS1="\[\e]2;\u@\H \w\a\]\[\e[0;37m\][\[\e[0;${col}m\]\u\[\e[0;37m\]@\[\e[0;34m\]\h \[\e[0;36m\]\W\[\e[0;37m\]]\$\[\e[0m\] "
fi
# Completion
trysource /usr/share/bash-completion/bash_completion
# Fuzzy matching all the way
trysource /usr/share/fzf/completion.bash
trysource /usr/share/fzf/key-bindings.bash

View file

@ -1,16 +0,0 @@
#!/usr/bin/env sh
#
# Bash / ZSH common environment variables and functions
#
export TIME_STYLE='+%Y-%m-%d %H:%M:%S'
export LESS=-R
export LESS_TERMCAP_mb=$'\E[1;31m' # begin blink
export LESS_TERMCAP_md=$'\E[1;36m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink
export LESS_TERMCAP_so=$'\E[01;44;33m' # begin reverse video
export LESS_TERMCAP_se=$'\E[0m' # reset reverse video
export LESS_TERMCAP_us=$'\E[1;32m' # begin underline
export LESS_TERMCAP_ue=$'\E[0m' # reset underline
eval $(dircolors --sh)

View file

@ -1,64 +0,0 @@
#!/usr/bin/env sh
#
# Bash / ZSH aliases and customizations
#
# Shell options
HISTSIZE=100000
HISTFILE="$HOME/.cache/shell_history"
## COMMAND CONFIGURATION
# Completion for existing commands
alias cp="cp -i --reflink=auto"
alias grep="grep --color=auto"
alias dd='dd status=progress'
alias rm='rm -v --one-file-system'
alias free='free -m'
alias diff='diff --color=auto'
alias dmesg='dmesg --ctime'
alias wget='wget --hsts-file $HOME/.cache/wget-hsts'
# [ -f ~/.local/bin/colorSchemeApplyFzf ] && . ~/.local/bin/colorSchemeApplyFzf # Only applies RGB colors...
FZF_DEFAULT_OPTS="--height 40% --layout=default"
FZF_CTRL_T_OPTS="--preview '[[ -d {} ]] && ls -l --color=always {} || [[ \$(file --mime {}) =~ binary ]] && file --brief {} || (highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null | head -500'"
FZF_COMPLETION_OPTS="${FZF_CTRL_T_OPTS}"
# Colored ls
_colored_ls() {
\ls -lh --color=always $@ | awk '
BEGIN {
FPAT = "([[:space:]]*[^[:space:]]+)";
OFS = "";
}
{
$1 = "\033[36m" $1 "\033[0m";
$2 = "\033[31m" $2 "\033[0m";
$3 = "\033[32m" $3 "\033[0m";
$4 = "\033[32m" $4 "\033[0m";
$5 = "\033[31m" $5 "\033[0m";
$6 = "\033[34m" $6 "\033[0m";
$7 = "\033[34m" $7 "\033[0m";
print
}
'
}
alias ll="_colored_ls"
alias la="_colored_ls -a"
# To keep until https://github.com/openssh/openssh-portable/commit/f64f8c00d158acc1359b8a096835849b23aa2e86
# is merged
function _ssh {
if [ "${TERM}" = "alacritty" ]
then
TERM=xterm-256color ssh "$@"
else
ssh "$@"
fi
}
alias ssh='_ssh'
## FUNCTIONS