Files
dotfiles/root/modules/bash.nix
T

73 lines
2.0 KiB
Nix

{ pkgs, ... }:
{
programs.bash = {
enable = true;
shellAliases = {
ff = "fastfetch";
ls = "lsd";
ll = "lsd -lFa";
};
initExtra = ''
mount-device () {
case "$1" in
usb)
sudo mount -m /dev/sda1 /mnt/usb
;;
microsd)
sudo mount -m /dev/mmcblk0p1 /mnt/microsd
;;
nvme)
sudo mount -m /dev/sda2 /mnt/nvme
;;
*)
echo "Usage: mount-device [usb|microsd|nvme]"
;;
esac
}
git_full_status() {
local branch ahead behind dirty
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ -n "$branch" ]]; then
# Check for uncommitted changes
if ! git diff --no-ext-diff --quiet --exit-code 2>/dev/null; then
dirty="●"
fi
# Get upstream info
local upstream
upstream=$(git rev-parse --abbrev-ref "@{upstream}" 2>/dev/null)
if [[ -n "$upstream" ]]; then
ahead=$(git rev-list --count "$upstream..HEAD" 2>/dev/null)
behind=$(git rev-list --count "HEAD..$upstream" 2>/dev/null)
fi
local status=" ($branch"
[[ -n "$dirty" ]] && status+="$dirty"
[[ $ahead -gt 0 ]] && status+=" ↑$ahead"
[[ $behind -gt 0 ]] && status+=" ↓$behind"
status+=")"
echo "$status"
fi
}
__prompt_command() {
local EXIT=$?
local TIME=$(date +%H:%M)
local git_status=$(git_full_status)
if [ $EXIT -eq 0 ]; then
PS1="\[\033[0;90m\][$TIME]\[\033[0m\] \[\033[1;31m\]\u@\h\[\033[0m\]:\[\033[1;34m\]\w\[\033[1;33m\]$git_status\[\033[0m\] # "
else
PS1="\[\033[0;90m\][$TIME]\[\033[0m\] \[\033[1;31m\]\u@\h\[\033[0m\]:\[\033[1;34m\]\w\[\033[1;33m\]$git_status \[\033[1;31m\][ERR:$EXIT]\[\033[0m\] # "
fi
}
PROMPT_COMMAND=__prompt_command
'';
};
}