os/programs/bash.nix

77 lines
2.5 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;
2024-11-21 21:06:08 +01:00
programs.bash.bashrcExtra = lib.concatStrings [
''
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"
2024-09-22 15:49:14 +02:00
2024-11-21 21:06:08 +01:00
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
2024-09-22 15:49:14 +02:00
2024-11-21 21:06:08 +01:00
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
''
# On mac we have to import brew
(if (os == "darwin") then ''
eval "$(/opt/homebrew/bin/brew shellenv)"
'' else ''
'')
];
2024-09-22 15:49:14 +02:00
programs.bash.shellAliases = {
chmod = "chmod --preserve-root";
chown = "chown --preserve-root";
2024-11-18 10:49:43 +01:00
ls = "ls --color=auto";
2024-09-22 15:49:14 +02:00
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-12-03 10:13:54 +01:00
rebuild = if (os == "linux") then ''
cd $HOME/.local/os &&
2024-12-10 15:05:15 +01:00
git pull &&
2024-12-10 15:03:39 +01:00
nix flake update --commit-lock-file &&
2024-12-03 10:13:54 +01:00
nixos-rebuild switch --flake "path:$HOME/.local/os#" --use-remote-sudo &&
2024-12-10 15:03:39 +01:00
git add . &&
git commit -m "update" &&
git push &&
2024-12-03 10:13:54 +01:00
cd -
2024-10-29 08:12:05 +01:00
'' else ''
2024-12-03 10:13:54 +01:00
cd $HOME/.local/os &&
2024-12-10 15:05:15 +01:00
git pull &&
2024-12-10 15:03:39 +01:00
nix flake update --commit-lock-file &&
2024-12-03 10:13:54 +01:00
home-manager switch &&
2024-12-10 15:03:39 +01:00
git add . &&
git commit -m "update" &&
git push &&
2024-12-03 10:13:54 +01:00
cd -
2024-09-22 15:49:14 +02:00
'';
":r" = "!!";
2024-10-29 08:12:05 +01:00
":wq" = "exit";
2024-12-03 10:13:54 +01:00
vim = "hx";
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-12-10 15:11:34 +01:00
DIRENV_LOG_FORMAT = "";
2024-09-22 15:49:14 +02:00
};
2024-11-18 10:49:43 +01:00
}