-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
31 lines (28 loc) · 1.28 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{ config, pkgs, ... }:
{
# Show git info in bash prompt and display a colorful hostname if using ssh.
programs.bash.promptInit = ''
export _JAVA_AWT_WM_NONREPARENTING=1
export GIT_PS1_SHOWDIRTYSTATE=1
source ${pkgs.gitAndTools.gitFull}/share/git/contrib/completion/git-prompt.sh
__prompt_color="1;33m"
# Alternate color for hostname if the generated color clashes with prompt color
__alternate_color="1;33m"
__hostnamecolor="$__prompt_color"
# If logged in with ssh, pick a color derived from hostname
if [ -n "$SSH_CLIENT" ]; then
__hostnamecolor="1;$(${pkgs.nettools}/bin/hostname | od | tr ' ' '\n' | ${pkgs.gawk}/bin/awk '{total = total + $1}END{print 30 + (total % 6)}')m"
# Fixup color clash
if [ "$__hostnamecolor" = "$__prompt_color" ]; then
__hostnamecolor="$__alternate_color"
fi
fi
__red="1;31m"
PS1='\n$(ret=$?; test $ret -ne 0 && printf "\[\e[$__red\]$ret\[\e[0m\] ")\[\e[$__prompt_color\]\u@\[\e[$__hostnamecolor\]\h \[\e[$__prompt_color\]\w$(__git_ps1 " [git:%s]")\[\e[0m\]\n$ '
'';
programs.bash.enableCompletion = true;
programs.bash.interactiveShellInit = ''
[[ -s "$HOME/.dircolors" ]] && eval `${pkgs.coreutils}/bin/dircolors $HOME/.dircolors`
'';
environment.homeBinInPath = true;
}