os/programs/bash.nix

52 lines
1.9 KiB
Nix
Raw Normal View History

2024-10-29 08:12:05 +01:00
{config, lib, pkgs, inputs, os, ...} : {
2024-09-22 15:49:14 +02:00
programs.bash.enable = true;
programs.bash.bashrcExtra = ''
if [ -n "$PS1" ]; then
NEW_PROMPT_COMMAND='
MY_PWD="$PWD"
[[ "$MY_PWD" =~ ^"$HOME"(/|$) ]] && MY_PWD="~''${MY_PWD#$HOME}"
TRIMMED_PWD=''${MY_PWD: -40};
TRIMMED_PWD=''${TRIMMED_PWD:-$MY_PWD}
[[ "''${#MY_PWD}" -ge 41 ]] && TRIMMED_PWD="…$TRIMMED_PWD"
SHELL_PREFIX=""
[[ -n "$IN_NIX_SHELL" ]] && SHELL_PREFIX="$SHELL_PREFIX "
[[ -n "$AWS_VAULT" ]] && SHELL_PREFIX="$SHELL_PREFIX 🔓"
[[ -n "$FLUTTER_ENV" ]] && SHELL_PREFIX="$SHELL_PREFIX "
[[ -n "$REACTNATIVE_ENV" ]] && SHELL_PREFIX="$SHELL_PREFIX "
'
if [ -n "''${PROMPT_COMMAND// /}" ]; then
PROMPT_COMMAND="$PROMPT_COMMAND
$NEW_PROMPT_COMMAND"
else
PROMPT_COMMAND="$NEW_PROMPT_COMMAND"
fi
unset NEW_PROMPT_COMMAND
export PS1="[\t \[\e[32m\]\u\[\e[m\]\[\e[32m\]@\[\e[m\]\[\e[32m\]\h\[\e[m\]]"'$SHELL_PREFIX'" \[\e[36m\]"'$TRIMMED_PWD'"\[\e[m\] \$ "
fi
2024-10-29 16:44:45 +01:00
eval "$(/opt/homebrew/bin/brew shellenv)"
2024-09-22 15:49:14 +02:00
'';
programs.bash.shellAliases = {
chmod = "chmod --preserve-root";
chown = "chown --preserve-root";
ls = "ls -Isnap --color";
df = "df -h -x squashfs -x tmpfs -x devtmpfs -x overlay -x revokefs-fuse";
free = "free -h";
toupper = "tr [:lower:] [:upper:]";
tolower = "tr [:upper:] [:lower:]";
2024-10-29 08:12:05 +01:00
rebuild = if (os == "linux") then ''
nixos-rebuild switch --flake "path:$HOME/.local/os#" --use-remote-sudo
'' else ''
home-manager switch
2024-09-22 15:49:14 +02:00
'';
":r" = "!!";
2024-10-29 08:12:05 +01:00
":wq" = "exit";
2024-09-22 15:49:14 +02:00
};
programs.bash.sessionVariables = {
NIX_SHELL_PRESERVE_PROMPT = 1;
NIXPKGS_ALLOW_UNFREE = 1;
2024-11-16 23:25:49 +01:00
HISTCONTROL = "ignoreboth:erasedups";
2024-09-22 15:49:14 +02:00
};
}