summary refs log tree commit diff stats
path: root/zsh
diff options
context:
space:
mode:
authorAlan Pearce2013-09-15 18:04:02 +0100
committerAlan Pearce2013-09-15 18:04:02 +0100
commit4315126ae683a32d3310f565629309c98cd11f97 (patch)
treeb9b514d92599b89b074eeea0ce37213504722d2d /zsh
parent273902cebbd5a2ded8905ab117341fca05627657 (diff)
downloadnixfiles-4315126ae683a32d3310f565629309c98cd11f97.tar.lz
nixfiles-4315126ae683a32d3310f565629309c98cd11f97.tar.zst
nixfiles-4315126ae683a32d3310f565629309c98cd11f97.zip
zsh: Refactor and improve cross-platform handling of ls options
Diffstat (limited to 'zsh')
-rwxr-xr-xzsh/zshrc37
1 files changed, 27 insertions, 10 deletions
diff --git a/zsh/zshrc b/zsh/zshrc
index d6ae52ea..bbfa9301 100755
--- a/zsh/zshrc
+++ b/zsh/zshrc
@@ -83,13 +83,9 @@ fi
 case $OSTYPE in
 	*gnu*)
 		os=gnu
-		ls_options="-v --group-directories-first --color=auto"
-		ls_isodate="--time-style=long-iso"
 		;;
 	freebsd*)
 		os=freebsd
-		ls_options="-p"
-		ls_isodate="-D '%F %k:%M'"
 		;;
 	darwin*)
 		os=osx
@@ -264,12 +260,33 @@ alias md='mkdir -p'
 alias rd='rmdir'
 alias .='source'
 
-if [[ $os == osx ]]
-then
-	ls='\gls'
-else
-	ls='\ls'
-fi
+ls='\ls'
+gnu_ls_options="-v --group-directories-first --color=auto"
+gnu_ls_isodate="--time-style=long-iso"
+bsd_ls_options="-p"
+bsd_ls_isodate="-D '%F %k:%M'"
+
+case $os in
+	osx)
+		if [[ -n $commands[gls] ]]
+		then
+			ls='\gls'
+			ls_options=$gnu_ls_options
+			ls_isodate=$gnu_ls_isodate
+		else
+			ls_options=$bsd_ls_options
+			ls_isodate=$bsd_ls_isodate
+		fi
+		;;
+	freebsd)
+		ls_options=$bsd_ls_options
+		ls_isodate=$bsd_ls_isodate
+		;;
+	gnu)
+		ls_options=$gnu_ls_options
+		ls_isodate=$gnu_ls_isodate
+		;;
+esac
 alias l="${ls} ${ls_options} -Bp"
 alias l1="${ls} ${ls_options} -1"
 alias ls="${ls} ${ls_options} -hF"