nix #11

Manually merged
geoffrey merged 113 commits from nix into main 2023-12-09 21:43:01 +01:00
4 changed files with 160 additions and 202 deletions
Showing only changes of commit ab4e33a825 - Show all commits

View file

@ -1,9 +1,77 @@
{ pkgs, config, ... }: { pkgs, config, lib, ... }:
{ {
programs = { programs =
let
commonRc = ''
# Colored ls
# TODO Doesn't allow completion
_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"
'';
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 = {
cp = "cp -i --reflink=auto";
grep = "grep --color=auto";
dd = "dd status=progress";
rm = "rm -v --one-file-system";
free = "free -m";
diff = "diff --color=auto";
dmesg = "dmesg --ctime";
wget = "wget --hsts-file ${config.xdg.cacheHome}/wget-hsts";
};
historySize = 100000;
historyFile = "${config.xdg.cacheHome}/shell_history";
in
{
home-manager.enable = true; home-manager.enable = true;
bash.enable = true; # Just in case the default shell is not ZSH, so we still have the variables bash = {
enable = true;
bashrcExtra = lib.strings.concatLines [
commonRc
''
shopt -s expand_aliases
shopt -s histappend
''
];
sessionVariables = commonSessionVariables;
historySize = historySize;
historyFile = historyFile;
historyFileSize = historySize;
historyControl = [ "erasedups" "ignoredups" "ignorespace" ];
shellAliases = commonShellAliases;
};
zsh = { zsh = {
enable = true; enable = true;
enableAutosuggestions = true; enableAutosuggestions = true;
@ -11,13 +79,25 @@
enableSyntaxHighlighting = true; enableSyntaxHighlighting = true;
# syntaxHighlighting.enable = true; # 23.11 syntax # syntaxHighlighting.enable = true; # 23.11 syntax
historySubstringSearch.enable = true; historySubstringSearch.enable = true;
initExtra = builtins.readFile ./zshrc.sh; initExtra = lib.strings.concatLines [
commonRc
(builtins.readFile ./zshrc.sh)
];
defaultKeymap = "viins"; defaultKeymap = "viins";
history = { history = {
size = 100000; size = historySize;
save = 100000; save = historySize;
path = historyFile;
expireDuplicatesFirst = true; expireDuplicatesFirst = true;
}; };
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 = { powerline-go = {
enable = true; enable = true;
@ -28,7 +108,7 @@
max-width = 25; max-width = 25;
cwd-max-dir-size = 10; cwd-max-dir-size = 10;
duration = "$( test -n \"$__TIMER\" && echo $(( $EPOCHREALTIME - $\{__TIMER:-EPOCHREALTIME})) || echo 0 )"; duration = "$( test -n \"$__TIMER\" && echo $(( $EPOCHREALTIME - $\{__TIMER:-EPOCHREALTIME})) || echo 0 )";
# UPST Implement this properly in home-manager # UPST Implement this properly in home-manager, would allow for bash support
}; };
extraUpdatePS1 = ''unset __TIMER''; extraUpdatePS1 = ''unset __TIMER'';
}; };
@ -71,12 +151,18 @@
trust = "ultimate"; trust = "ultimate";
}]; }];
}; };
fzf.enable = true; 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 # TODO highlight or bat
nix-index = { nix-index = {
enable = true; enable = true;
enableZshIntegration = true; enableZshIntegration = true;
}; };
less.enable = true;
}; };
home = { home = {
stateVersion = "23.05"; stateVersion = "23.05";
@ -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