You are not logged in.

#1 2009-05-04 05:59:46

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

[bash] NEITHER $cat file|bash NOR $ bash file DOESN'T WORK while...

PWDLENGTH=` pwd  | sed 's/^\/home\/sk/\~/' | sed  's/.*\/\(.*\/.*\/.*\)$/\1/' | wc -c `;LENGTH1=` echo -n "┌─────────────────────[" | wc -m `;LENGTH2=` echo -n "]───────────[12:35:58]" | wc -m  `;let EMPTY="$COLUMNS"-"$PWDLENGTH"-"$LENGTH1"-"$LENGTH2"+1;LOW=1;FILL=$( while [ "$EMPTY" -ge "$LOW" ] ; do echo -n '─' ; ((EMPTY--)) ;done );echo -n $FILL

just this little code, saved in a file at /path/to/file

gets me scratching

I did 3 things::

$ bash /path/to/file
THEN,THERE IS NO OUTPUT!!

$ cat  /path/to/file | bash
THEN, THERE IS NO OUTPUT!!

$ cat /path/to/file
THEN,MANUALLY PASTE THE LINE SHOWN ABOVE,THEN,ENTER
THEN,THERE IS THE OUTPUT....

what is this all about??


This silver ladybug at line 28...

Offline

#2 2009-05-04 06:29:53

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [bash] NEITHER $cat file|bash NOR $ bash file DOESN'T WORK while...

Let me explain what i wanted to do.

PS1="\[\033[0;34m\]┌─────────────────────[\[\033[0;36m\]\$( pwd  | sed 's/^\/home\/sk/\~/' | sed  's/.*\/\(.*\/.*\/.*\)$/\1/' )\[\033[0;34m\]]───────────[\[\033[0;34m\]\T\[\033[0;34m\]]\n└─+\u+ >\[\033[m\]"

this get me a bash prompt like this

┌─────────────────────[~/BG]───────────[02:08:41]
└─+sk+ >

whose width would always change when present working directory changes

i want the width fixed, no matter which pwd
so i used $COLUMNS, which is the width of the terminal window
i want some extra "─"s to fill the empty spaces to get the width extended to $COLUMNS,so it should finally look like

┌─────────────────────[~/BG]─────────────────────────────────────────[02:08:41]
└─+sk+ >
$ cd BLUE
┌─────────────────────[~/BG/BLUE]─────────────────────────────────────[02:08:41]
└─+sk+ >
$ cd 
┌─────────────────────[~]────────────────────────────────────────────[02:08:41]
└─+sk+ >

the 'PS1=' line is put in .bashrc;and i inserted a function

FitWid () {
PWDLENGTH=` pwd  | sed 's/^\/home\/sk/\~/' | sed  's/.*\/\(.*\/.*\/.*\)$/\1/' | wc -c `
LENGTH1=` echo -n "┌─────────────────────[" | wc -m `
LENGTH2=` echo -n "]───────────[12:35:58]" | wc -m  `
let EMPTY="$COLUMNS"-"$PWDLENGTH"-"$LENGTH1"-"$LENGTH2"+1
LOW=1
FILL=$( while [ "$EMPTY" -ge "$LOW" ] ; do echo -n '─' ; ((EMPTY--)) ;done )
echo -n $FILL
}

right before 'PS1=' line

then modified the 'PS1=' line to

PS1="\[\033[0;34m\]┌─────────────────────[\[\033[0;36m\]\$( pwd  | sed 's/^\/home\/sk/\~/' | sed  's/.*\/\(.*\/.*\/.*\)$/\1/' )\[\033[0;34m\]]──\$( FitWid )─────────[\[\033[0;34m\]\T\[\033[0;34m\]]\n└─+\u+ >\[\033[m\]"

then i did $ . ~/.bashrc
it worked, but just for the first time
when i changed pwd to ~/BG,  the width gets too long and wrapped
i checked it and found the FitWid part didn't work well
the length it generated was never changing
seems FitWid was run only once and later the result get used multiple times
so i reluctantly put it in a separate file to run, with $ bash /path/to/file, and with no result....
Anybody help?

Last edited by lolilolicon (2009-05-04 06:31:17)


This silver ladybug at line 28...

Offline

#3 2009-05-04 07:45:37

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [bash] NEITHER $cat file|bash NOR $ bash file DOESN'T WORK while...

Congrats!

BEHOLD  EVERYBODY!
In this following line, do escape "$ " whith a preceeding "\"

PS1="\[\033[0;34m\]┌─────────────────────[\[\033[0;36m\]\${newPWD}\[\033[0;34m\]]\${fill}─────────[\[\033[0;34m\]\T\[\033[0;34m\]]\n└─+\u+ >\[\033[m\]"


well... the weird stuff up there is still weird for me....
Anyone who come across the post..Don't save your generosity's helping hand!


This silver ladybug at line 28...

Offline

#4 2009-05-04 09:27:06

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [bash] NEITHER $cat file|bash NOR $ bash file DOESN'T WORK while...

IF YOU'VE GOT TIME, plz take a look here, i got another problem

http://bbs.archlinux.org/viewtopic.php? … 2#p547662#

kinda a condition with the PS1 stuff...

Think it should be really simple to you guys,

mighty mighty help me quickly @@


This silver ladybug at line 28...

Offline

#5 2009-05-04 10:42:07

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [bash] NEITHER $cat file|bash NOR $ bash file DOESN'T WORK while...

lolilolicon - please don't use caps like that. It's unnecessary. Also, do not cross-reference your threads/posts. You should have posted your issue fom the "What's your PS1?" thread here instead.

Offline

#6 2009-05-04 10:53:31

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [bash] NEITHER $cat file|bash NOR $ bash file DOESN'T WORK while...

tomk
ok, i thought those were two different issues. initially
since the one posted in this thread in the first place was simply weird..
i use caps randomly...sometimes..lol,
sorry for that.. as well as my poor english


This silver ladybug at line 28...

Offline

Board footer

Powered by FluxBB