Skip to content

Instantly share code, notes, and snippets.

@gak
Created June 10, 2013 06:43
Show Gist options
  • Save gak/5746941 to your computer and use it in GitHub Desktop.
Save gak/5746941 to your computer and use it in GitHub Desktop.
My custom fish prompt code explained at http://geraldkaszuba.com/tweaking-fish-shell/
# Show disk usage when low
set -l du (df / | tail -n1 | sed "s/ */ /g" | cut -d' ' -f 5 | cut -d'%' -f1)
if test $du -gt 80
error du $du%%
end
@pawelkl-zz
Copy link

instead of line 2:

set -l du (df / | tail -n1 | sed "s/ */ /g" | cut -d' ' -f 5 | cut -d'%' -f1)

much shorter way:

set -l du (df / | grep -Eo '([0-9]{1,3})%')

2 commands in subshell instead of 5! xD
EDIT: for exact string (without "%" and without using cut) you could use

set -l du (df / | sed -En 's/.*[[:space:]]([0-9]{1,3})%.*/\1/p')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment