LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-02-2013, 08:58 AM   #1
Ibis
LQ Newbie
 
Registered: Mar 2013
Location: Rome
Distribution: Slackware
Posts: 5

Rep: Reputation: Disabled
Problem with script bash to show the current folder


Hi i'm a young novice linux user.
I found this script to show in the prompt bash the current directory

Code:
 #!/bin/bash

function prompt_command {
	# save the current position
tput sc
	# backwash is where to position the cursor
	# to write the whole current working directory
	# we back up 2 more for the brackets
let backwash=$(tput cols)-$(echo $(pwd) | wc -m)-2
	# position the cursor at Y=0, X=calculated length
tput cup 0 ${backwash}
	# set foreground color, bold
tput setaf 4 ; tput bold
	# wrap the full path in brackets
echo -n "["
	# set the color of the current path
tput setaf 6
	# show the path
echo -n "$(pwd)"
	# set the color of the closing bracket
tput setaf 4 ; tput bold
	# show the closing bracket
echo -n "]"
	# return the cursor to the saved position
tput rc
}

PROMPT_COMMAND=prompt_command

GREEN="\[$(tput setaf 2 ; tput bold)\]"
WHITE="\[$(tput setaf 7 ; tput bold)\]"
NO_COLOUR="\[$(tput sgr0)\]"
case $TERM in
	xterm*|rxvt*)
	TITLEBAR='\[\033]0;\u@\h \007\]'
	;;
    *)
	TITLEBAR=""
	;;
esac

PS1="${TITLEBAR}\
$GREEN\u@\h \
$WHITE\$$NO_COLOUR "
PS2='> '
PS4='+ '
And that's the problem:


http://www.fileden.com/files/2008/1/4/1679401/term.jpg

Thanks for help and sorry for my bad english!

Last edited by Ibis; 03-02-2013 at 10:04 AM.
 
Old 03-02-2013, 09:43 AM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,310
Blog Entries: 5

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
http://wiki.bash-hackers.org/doku.php
 
Old 03-02-2013, 10:06 AM   #3
Ibis
LQ Newbie
 
Registered: Mar 2013
Location: Rome
Distribution: Slackware
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks, I'll look for a solution

EDIT:
It was very simple! I just added these lines:
Code:
tput cup 0 0
tput el
I don't think that it's useful, but if could help someone that's the code of the script:

Code:
#!/bin/bash

function prompt_command {
	# save the current position
tput sc
	# move the cursor at 0 0 and delete the line
tput cup 0 0
tput el
	# backwash is where to position the cursor
	# to write the whole current working directory
	# we back up 2 more for the brackets
let backwash=$(tput cols)-$(echo $(pwd) | wc -m)-2
	# position the cursor at Y=0, X=calculated length
tput cup 0 ${backwash}
	# set foreground color, bold
tput setaf 4 ; tput bold
	# wrap the full path in brackets
echo -n "["
	# set the color of the current path
tput setaf 6
	# show the path
echo -n "$(pwd)"
	# set the color of the closing bracket
tput setaf 4 ; tput bold
	# show the closing bracket
echo -n "]"
	# return the cursor to the saved position
tput rc
}

PROMPT_COMMAND=prompt_command

GREEN="\[$(tput setaf 2 ; tput bold)\]"
WHITE="\[$(tput setaf 7 ; tput bold)\]"
NO_COLOUR="\[$(tput sgr0)\]"
case $TERM in
	xterm*|rxvt*)
	TITLEBAR='\[\033]0;\u@\h \007\]'
	;;
    *)
	TITLEBAR=""
	;;
esac

PS1="${TITLEBAR}\
$GREEN\u@\h \
$WHITE\$$NO_COLOUR "
PS2='> '
PS4='+ '
P.S. it doesn't work as root

Last edited by Ibis; 03-02-2013 at 11:08 AM.
 
Old 03-03-2013, 08:33 AM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,193
Blog Entries: 3

Rep: Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425Reputation: 1425
Moderator Response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script that will execute all *.sh in a folder trettet Linux - Newbie 2 04-09-2012 05:34 AM
[SOLVED] Bash dialog show infobox script on RHEL 6.2 luxus Programming 2 03-27-2012 02:04 AM
cat and grep in a bash script do not show results desired. okos Linux - Software 4 11-08-2009 11:39 PM
Do not show ls error in bash script Rindert Linux - General 2 08-18-2006 05:28 PM
making select show its menu in a bash script? zidane_tribal Programming 6 05-02-2005 05:52 AM


All times are GMT -5. The time now is 08:03 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration