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.
This thread has been closed and replaced with the following thread:
Subject: BASH custom prompt Name:
Email:
I've been hacking around with the BASH custom prompt and I made myself a prompt that shows the current command number, but there's a problem: I want the number to always be four-digit, so that [0004][haxus:~] and [1209][haxus:~] align nicely.
>>9
Details please, this doesn't seem to be the C printf I know.
Name:
Anonymous2009-04-12 18:16
>>8
Is having the number displayed useful? I mostly use the function: hgrep ()
{
history | grep $1 | grep -v "hgrep $1"
}
Is any way to modify ! ^r searching to act like MATLAB's command history? i.e. type a couple letters, then hit the up arrow to scroll through matching commands.
Name:
Anonymous2009-04-12 18:19
So I have printf "%0.4d\n", okay, but how do I get the command number?
Name:
Anonymous2009-04-12 18:23
Does the site title say `4chan BBS - Pimp my bash' to you?
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.