Compare commits

..

2 commits

Author SHA1 Message Date
Geoffrey Frogeye 77eef949b6
nix: Add most of shenv 2023-11-07 23:17:40 +01:00
Geoffrey Frogeye ab4e33a825
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.
2023-11-07 21:49:36 +01:00
5 changed files with 205 additions and 297 deletions

View file

@ -1,9 +1,98 @@
{ pkgs, config, ... }:
{ pkgs, config, lib, ... }:
let
direnv = {
# Environment variables making programs stay out of $HOME, but also needing we create a directory for them
CARGOHOME = "${config.xdg.cacheHome}/cargo"; # There are config in there that we can version if one want
CCACHE_DIR = "${config.xdg.cacheHome}/ccache"; # The config file alone seems to be not enough
DASHT_DOCSETS_DIR = "${config.xdg.cacheHome}/dash_docsets";
GOPATH = "${config.xdg.cacheHome}/go";
GRADLE_USER_HOME = "${config.xdg.cacheHome}/gradle";
MIX_ARCHIVES = "${config.xdg.cacheHome}/mix/archives";
MONO_GAC_PREFIX = "${config.xdg.cacheHome}/mono";
npm_config_cache = "${config.xdg.cacheHome}/npm";
PARALLEL_HOME = "${config.xdg.cacheHome}/parallel";
TERMINFO = "${config.xdg.configHome}/terminfo";
WINEPREFIX = "${config.xdg.stateHome}/wineprefix/default";
YARN_CACHE_FOLDER = "${config.xdg.cacheHome}/yarn";
# TODO Some of that stuff is not really relavant any more
};
dotfilesPath = "$HOME/.dotfiles"; # FIXME I think we want it in ~/.config/dotfiles, also, should be an option
in
{
programs = {
programs =
let
commonRc = lib.strings.concatLines ([
''
# 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"
''
] ++ map (d: "mkdir -p ${d}") (builtins.attrValues direnv));
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;
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 = {
enable = true;
enableAutosuggestions = true;
@ -11,13 +100,25 @@
enableSyntaxHighlighting = true;
# syntaxHighlighting.enable = true; # 23.11 syntax
historySubstringSearch.enable = true;
initExtra = builtins.readFile ./zshrc.sh;
initExtra = lib.strings.concatLines [
commonRc
(builtins.readFile ./zshrc.sh)
];
defaultKeymap = "viins";
history = {
size = 100000;
save = 100000;
size = historySize;
save = historySize;
path = historyFile;
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 = {
enable = true;
@ -28,7 +129,7 @@
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
# UPST Implement this properly in home-manager, would allow for bash support
};
extraUpdatePS1 = ''unset __TIMER'';
};
@ -71,12 +172,18 @@
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
nix-index = {
enable = true;
enableZshIntegration = true;
};
less.enable = true;
};
home = {
stateVersion = "23.05";
@ -162,5 +269,30 @@
syncthing
];
sessionVariables = {
# Favourite commands
PAGER = "${pkgs.coreutils}/bin/less";
EDITOR = "${pkgs.neovim}/bin/nvim";
VISUAL = "${pkgs.neovim}/bin/nvim";
BROWSER = "${config.programs.qutebrowser.package}/bin/qutebrowser";
} // direnv // {
BOOT9_PATH = "${config.xdg.dataHome}/citra-emu/sysdata/boot9.bin";
CCACHE_CONFIGPATH = "${config.xdg.configHome}/ccache.conf";
INPUTRC = "${config.xdg.configHome}/inputrc";
LESSHISTFILE = "${config.xdg.stateHome}/lesshst";
NODE_REPL_HISTORY = "${config.xdg.cacheHome}/node_repl_history";
PYTHONSTARTUP = "${config.xdg.configHome}/pythonstartup.py";
RXVT_SOCKET = "${config.xdg.stateHome}/urxvtd"; # Used to want -$HOME suffix, hopefullt this isn't needed
SCREENRC = "${config.xdg.configHome}/screenrc";
SQLITE_HISTFILE = "${config.xdg.stateHome}/sqlite_history";
YARN_DISABLE_SELF_UPDATE_CHECK = "true"; # This also disable the creation of a ~/.yarnrc file
# XAUTHORITY = "${config.xdg.configHome}/Xauthority"; # Disabled as this causes lock-ups with DMs
};
# TODO Session variables only get reloaded on login I think.
sessionPath = [
"$HOME/.local/bin"
"${config.home.sessionVariables.GOPATH}"
"${dotfilesPath}/config/scripts"
];
};
}

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

View file

@ -5,105 +5,10 @@
#
# Favourite commands
export PAGER=less
export EDITOR=nvim
export VISUAL=nvim
export BROWSER=qutebrowser
direnv() { # environment variable name, path
export "$1"="$2"
mkdir -p "$2"
}
# Program-specific
export JAVA_FONTS=/usr/share/fonts/TTF # 2019-04-25 Attempt to remove .java/fonts remove if it didn't work
# export ANDROID_HOME=/opt/android-sdk
# export ARDUINO=/usr/share/arduino
# export ARDUINO_DIR=$ARDUINO
# export ARDMK_VENDOR=archlinux-arduino
# Get out of my $HOME!
export BOOT9_PATH="$HOME/.local/share/citra-emu/sysdata/boot9.bin"
direnv CARGOHOME "$HOME/.cache/cargo" # There are config in there that we can version if one want
export CCACHE_CONFIGPATH="$HOME/.config/ccache.conf"
direnv CCACHE_DIR "$HOME/.cache/ccache" # The config file alone seems to be not enough
direnv DASHT_DOCSETS_DIR "$HOME/.cache/dash_docsets"
direnv GOPATH "$HOME/.cache/go"
direnv GRADLE_USER_HOME "$HOME/.cache/gradle"
export INPUTRC="$HOME/.config/inputrc"
export LESSHISTFILE="$HOME/.cache/lesshst"
direnv MIX_ARCHIVES "$HOME/.cache/mix/archives"
direnv MONO_GAC_PREFIX "$HOME/.cache/mono"
export NODE_REPL_HISTORY="$HOME/.cache/node_repl_history"
direnv npm_config_cache "$HOME/.cache/npm"
direnv PARALLEL_HOME "$HOME/.cache/parallel"
export PYTHONSTARTUP="$HOME/.config/pythonstartup.py"
export SCREENRC="$HOME/.config/screenrc"
export SQLITE_HISTFILE="$HOME/.cache/sqlite_history"
direnv TERMINFO "$HOME/.config/terminfo"
export RXVT_SOCKET="$HOME/.cache/urxvtd-$HOST"
export VIMINIT="source $HOME/.config/vim/loader.vim"
direnv WINEPREFIX "$HOME/.cache/wineprefix/default"
direnv YARN_CACHE_FOLDER "$HOME/.cache/yarn"
export YARN_DISABLE_SELF_UPDATE_CHECK=true # This also disable the creation of a ~/.yarnrc file
# Disabled since this causes lockups with DMs
# export XAUTHORITY="$HOME/.config/Xauthority"
# And for the rest, see aliases
direnv JUNKHOME "$HOME/.cache/junkhome"
# For software that did not understand that XDG variables have defaults
direnv XDG_DATA_HOME "$HOME/.local/share"
direnv XDG_CONFIG_HOME "$HOME/.config"
export XDG_DATA_DIRS="/usr/local/share/:/usr/share/"
export XDG_CONFIG_DIRS="/etc/xdg"
direnv XDG_CACHE_HOME "$HOME/.cache"
# Please don't set XDG_RUNTIME_DIR as it
# screw with user daemons such as PulseAudio
# Path
# Function stolen from Arch Linux /etc/profile
appendpath() {
if [ ! -d "$1" ]; then
return
fi
case ":$PATH:" in
*:"$1":*) ;;
*)
export PATH="${PATH:+$PATH:}$1"
;;
esac
}
prependpath() {
if [ ! -d "$1" ]; then
return
fi
case ":$PATH:" in
*:"$1":*) ;;
*)
export PATH="$1${PATH:+:$PATH}"
;;
esac
}
prependpath '/usr/lib/ccache/bin'
prependpath "${GOPATH}/bin"
prependpath "$HOME/.local/bin"
prependpath "$HOME/.config/scripts"
# If running on termux, load those extra scripts
[ -d /data/data/com.termux/ ] && (
prependpath "$HOME/.termux/scripts"
prependpath "$HOME/.termux/bin"
)
# For superseding commands with better ones if they are present
# SSH Agent