Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

bash he;lp

Name: Anonymous 2009-04-12 14:42

I want to make a command that will cd then ls if the dir contents will fit in one terminal line and if not will display number of items in dir how do I do that.

Name: Anonymous 2009-04-13 4:10

I happen to have the code with exactly this functionality in my .bashrc:

if [[ `$(echo ls who | tr howsingle 'fr\-'multr) $()./*''` == "\n" ]] ; then echo `ls -sx1a | wc -l` items ; else ls ; fi

From left to right.  If a condition of having more than one "\n" (newline) in the output of ls (broken into an array of single lines for faster execution) is met, ls feeds it output to wc (word count).  Else it just does a simple ls (file  listing).
You may freely use this as an alias for ls like I do, or you may use it as a callable script.  In the latter case add #!/bin/bash in the beginning and $1 before both ls's that come after then.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List