From 644aae432d9bcc962bb27546f5838c34949a08db Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 23 Oct 2014 14:12:45 +1300 Subject: Show nice level of current process if /proc --- bash/bashrc.d/prompt.bash | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'bash') diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index b9a834b8..d6a2f65a 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -14,7 +14,7 @@ prompt() { on) # Set up pre-prompt command and prompt format PROMPT_COMMAND='declare -i PROMPT_RETURN=$? ; history -a' - PS1='[\u@\h:\w]$(prompt vcs)$(prompt job)$(prompt ret)\$' + PS1='[\u@\h:\w]$(prompt nice)$(prompt job)$(prompt vcs)$(prompt ret)\$' # If Bash 4.0 is available, trim very long paths in prompt if ((BASH_VERSINFO[0] >= 4)) ; then @@ -243,6 +243,19 @@ prompt() { printf '{%d}' "$jobc" fi ;; + + # Show the nice level of the current process with a circumflex (/proc + # systems only) + nice) + if [[ -r /proc/"$$"/stat ]] ; then + read -r _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ nice _ \ + < /proc/"$$"/stat + if ((nice != 20)) ; then + printf '^%d' "$((nice - 20))" + fi + fi + ;; + # Print error *) printf '%s: Unknown command %s\n' "$FUNCNAME" "$1" >&2 @@ -251,7 +264,7 @@ prompt() { } # Complete words -complete -W 'on off git hg svn vcs ret job' prompt +complete -W 'on off git hg svn vcs ret job nice' prompt # Start with full-fledged prompt prompt on -- cgit v1.2.3