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

Pages: 1-

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-12 14:44

use zsh instead
it's better

Name: Anonymous 2009-04-12 15:08

>>1
PROTIP: use wc.

Name: Anonymous 2009-04-12 15:19

if [ `ls | wc -w` -gt 3 ]; then ls | wc -l; else ls; fi

Assuming reasonable terminal width and filenames of reasonable length.

Name: Anonymous 2009-04-12 15:24

>>4
Nono not hardcoded using terminal width variable.

Name: Anonymous 2009-04-12 15:28

>>5
Enjoy rewriting most of the display logic in ls in your bash script.
However, two hints:

echo $COLUMNS
tput cols

The rest is just simple math and a lot of writing.

Name: Anonymous 2009-04-12 16:48

>>6
I will, along with my job.

Name: Anonymous 2009-04-12 17:49

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.

Name: Anonymous 2009-04-12 18:13

>>8
Use printf.

Name: Anonymous 2009-04-12 18:16

>>9
Details please, this doesn't seem to be the C printf I know.

Name: Anonymous 2009-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: Anonymous 2009-04-12 18:19

So I have printf "%0.4d\n", okay, but how do I get the command number?

Name: Anonymous 2009-04-12 18:23

Does the site title say `4chan BBS - Pimp my bash' to you?

Name: Anonymous 2009-04-12 18:24

>>13
Kinda.

Name: Anonymous 2009-04-12 18:27

>>13
brb, greasemonkey

Name: Anonymous 2009-04-12 18:28

>>12
The same way you got it in >>8. Moron.
man 1 printf

Name: Anonymous 2009-04-12 18:35

>>16
I did that with \#, that doesn't seem to work with printf.

Name: Anonymous 2009-04-12 18:39

[printf "%0.4d" 1][haxus:~]

I DON`T THINK YOU THOUGHT YOUR CUNNING PLAN ALL THE WAY THROUGH

Name: Anonymous 2009-04-12 18:42

Never mind, it worked. Thanks /prog!

Name: Anonymous 2009-04-12 18:53

>>18
Facepalms are in order.

Name: Anonymous 2009-04-12 19:00

>>20
YHBTIPT

Name: Anonymous 2009-04-12 19:59

>>21
NYJMUA

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.

Name: SAGE GOES IN EVERY FIELD 2009-04-13 4:12

>>23
WHY DID YOU HELP HIM‽‽‽

Name: Anonymous 2009-04-13 4:56

>>23
if [ $(ls -m | wc -l) -gt 1 ]; then ls -1 | wc -l; else ls -m; fi

Name: Anonymous 2009-04-13 5:01

>>25
ls -1 | wc -l
How enterprise of you.

Name: Anonymous 2009-04-13 5:16

>>25
well it is better (less ENTERPRISE) than >>23's ls -sx1a | wc -l...

Name: Anonymous 2009-04-13 5:32

>>25
You had completely missed the point of >>23.

Name: Anonymous 2009-04-13 5:43

>>28
The point of >>23 is that it's pointless.

Name: Anonymous 2009-04-13 6:59

>>29
Observe >>23 in action before you critique it; you may find a special treat.

Name: Anonymous 2009-04-13 17:22

>>30
i found a stale cheeto

Name: Anonymous 2013-09-01 20:28



::::::::::: ::: :: : : rァ' ̄77ヽ.    iア'ヽ、          /
:::::::: ::: :: : :  }!::::::::!{:::::i,}  r/:::::/,ハ、        |    ・
::: ::: :: : :   '、::::::ヽ、」|‐-r'::::::/ソ:::::!{._         !    ・
:: :: : :      .>;-‐ァ'`'ー'i-<__ン´ `' 、      |    ・
: :      / く__/    '、__,>   、   ヽ.    !
      ./ /  ;' __,/! ,ハ /ー!-‐/!.  ';. '; ';  ∠.
     .,.' ;'  ! ./_」/ レ' ァ'‐_-'、! __.! ! i    `''ー-----‐
     く.; !   !ァ'´;-、    i´ ハ Y´ ,.イ  !
      i !   !i  i_,リ    ゝ‐'’ !__,イ/  !     ,. -‐‐-、
     └i__,.ヘ,ハ .,.,.   ____   ""/ |   ,.'    / ,.-‐-、 i
      く/   !、.,  └‐┘ ,/  ハ /(    i  i 、__ノ
       ;'   ! ./`"7''=r‐ァ'´   /'´ノ)::::)   〉 `'ー-‐'
    ____ i.   Vヽrイ__!/   _,.イ`ヾ、!__」{  ノ
  ;'´,.-、` '、  r!:::`ヽ!7‐ァ'--‐ァ''´ ,rンヽ,
  i '、┘ ノ,i>く二ソi-iヽ、::::::/!/ r'/:::::::::::';
  ノ    ̄ rく   iソ::::/!´`ヽ、>'  /ソ:::::::::::::::i>
       `ヘ._ r!::::/、  ,ンi:::;ゝ /7,!-、r、_ノ  厄
         i`'ヽ'|:::) ノ::::}L/::V´  /'´

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