From: Frank Terbeck Date: Mon, 28 Nov 2011 21:44:22 +0000 (+0100) Subject: zshrc: Move lsdisk to its own file X-Git-Tag: v0.5.0~61 X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=919ba75cf1d271284dbef293bf372cf279914bcf zshrc: Move lsdisk to its own file And make the code vaguely readable... Signed-off-by: Frank Terbeck --- diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 0cafc3e..93055d8 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -2924,26 +2924,6 @@ purge() { fi } -#f5# show labels and uuids of disk devices -if is439 && [[ -d /dev/disk/by-id/ ]]; then - lsdisk() { - emulate -L zsh - setopt extendedglob - local -a -U disks - local -A mountinfo - disks=( /dev/disk/by-id/*(@:A) ) - [[ -r /proc/mounts ]] && for cline ( "${(f)$(}/${dev:t}/size(N) ) \ - print -f " Size: %.3f GiB (%d Byte)\n" $(($(<$sysdevsize)/(2.0*1024.0*1024.0))) $(($(<$sysdevsize)*512)) - - print -f " Id: %s\n" /dev/disk/by-id/*(@e/'[[ ${REPLY:A} == $dev ]]'/N:t) - done - } -fi - # Translate DE<=>EN # 'translate' looks up fot a word in a file with language-to-language # translations (field separator should be " : "). A typical wordlist looks diff --git a/usr_share_grml/zsh/functions/lsdisk b/usr_share_grml/zsh/functions/lsdisk new file mode 100644 index 0000000..ef0a64e --- /dev/null +++ b/usr_share_grml/zsh/functions/lsdisk @@ -0,0 +1,40 @@ +# show labels and uuids of disk devices +emulate -L zsh +setopt extendedglob + +local -a -U disks +local -A mountinfo + +disks=( /dev/disk/by-id/*(N@:A) ) + +if (( ${#disks} == 0 )); then + printf 'No disks detected.\n' + return 1 +fi + +if [[ -r /proc/mounts ]]; then + for cline in "${(f)$(}/${dev:t}/size(N) + do + print -f " Size: %.3f GiB (%d Byte)\n" \ + $(($(<$sysdevsize)/(2.0*1024.0*1024.0))) \ + $(($(<$sysdevsize)*512)) + done + + print -f " Id: %s\n" /dev/disk/by-id/*(@e/'[[ ${REPLY:A} == $dev ]]'/N:t) +done