Re: using `myscript.sh` to change current env
On Sat, Sep 07, 2013 at 04:35:09PM +1000, Zenaan Harkness wrote: > I want to have a script, to change between a few prompts per the arg > supplied. This is so I can quickly change from my glorious > bells-and-whistles prompt to a plain prompt (eg for cut and paste to > debian-user, just "$ " or "# " depending on current user) to a > timestamped prompt (when I have some long-running process, and I want > to see when it finished) etc. Not a direct solution to your problem, but zsh has a "prompt" command which will allow you to install a new prompt theme with a single command. For day-to-day work zsh is comparable to bash (the learning curve is much smaller than between e.g. bash and tcsh), but there's a lot of extra power available built-in. signature.asc Description: Digital signature
Re: Re: using `myscript.sh` to change current env
Dear Zenaan, I tried the same by putting those code in a script - myprompt.bash like below #!/usr/bin/bash PS1=': ' In terminal, when I run like '. ./myprompt.bash', it is working as expected. Also I tried with alias like below and that also worked for me. alias myprompt="export PS1=': '" Simply to run like 'myprompt'(without quotes) in terminal. Regards, Balamurugan R On 09/07/2013 01:08 PM, Zenaan Harkness wrote: On 9/7/13, der.hans wrote: Am 07. Sep, 2013 schw�tzte Zenaan Harkness so: moin moin Zenaan, Rather than all the convolutions of command substitution, how about just using a function that's in your profile or bashrc? $ cat /tmp/bashrc function changeps() { export PS1= ' } $ . /tmp/bashrc $ changeps : Add arguments to the fx() for your different options :). Ahh. Even easier, and better (no tmpfile). Wunderbah! Thank you. Appreciated, Zenaan -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/522be8ce.9010...@gmail.com
Re: using `myscript.sh` to change current env
On 9/7/13, der.hans wrote: > Am 07. Sep, 2013 schwätzte Zenaan Harkness so: > > moin moin Zenaan, > > Rather than all the convolutions of command substitution, how about just > using a function that's in your profile or bashrc? > > $ cat /tmp/bashrc > function changeps() { > export PS1=': ' > } > $ . /tmp/bashrc > $ changeps > : > > Add arguments to the fx() for your different options :). Ahh. Even easier, and better (no tmpfile). Wunderbah! Thank you. Appreciated, Zenaan -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/CAOsGNSRLCCP5vuCL9g10La87yLyV=tggedcfpunahvi9fcv...@mail.gmail.com
Re: using `myscript.sh` to change current env
On 9/7/13, Zenaan Harkness wrote: > On 9/7/13, Zenaan Harkness wrote: >> So I thought, run the script in a subshell, executing the result, like: >> $ `ps1` >> >> The following 3-line script is meant to test exactly this: >> >> #!/bin/bash >> PS1=': ' >> echo "export PS1=$PS1" After trying a few other options, it appears that the only simple solution is to type a few extra chars: PS1=`ps1` where the ps1 script spits out the prompt content, not the command to change the prompt. And that leads me to another potential solution, see below. This is reasonable given that all I want to do is embed my 'preferred alternative prompts' in a script, so I can pass in a cmd line arg into ps1 to pick a prompt on the fly, without having to go in and cut-and-paste, or tediously locate the actual location of my ps1 script every time "source"ing it. Now, the alternate solution arises from the above, and from the /etc/network/interfaces suggestion made yesterday by someone: ps1 script can create itself a temporary file, and echo the command to source that file. This might be solution solved ... exploring now ... By the way, I've searched the net, from stackexchange to comp.unix.shell, and have not yet found a solution to this seemingly so simple "problem". Voila! It works! My .bashrc used to have: source $BASHDIR/prompt Now I just use `ps1` (after setting my path to include my bin/ dir with the ps1 script of course). And here it is, script "ps1" to modify parent shell environment (by running the script with command execution): #!/bin/bash # Bash script to change parent environment. # Relies on storing the desired changes into a tmp file # (see TMPFILE below), # as well as on using command substitution when script is run. # So therefore must be run as eg: `ps1` GREEN_PROMPT='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \D{%Y%m%d} \t\[\033[00;36m\] \[\033[01;33m\]\w\[\033[00m\]\$ ' case "$1" in 0) # simplest prompt (zero jazz): case `whoami` in root) PS1='# ' ;; *) PS1='\$ ' ;; esac ;; t*) # 't'imed - add date-time stamp to prompt: case `whoami` in root) PS1='\D{%Y%m%d}-\t\# ' ;; *) PS1='\D{%Y%m%d}-\t\$ ' ;; esac ;; *) # default: reset back to my preferred default prompt: case `whoami` in root) PS1='\D{%Y%m%d}-\t\# ' ;; *) case "$TERM" in xterm* | rxvt* | linux | screen* | cygwin) PS1=$GREEN_PROMPT ;; *) PS1='${debian_chroot:+($debian_chroot)}\u@\h:$(__git_ps1 "%s"):\w\$ ' ;; esac ;; esac ;; esac TMPFILE=~/.`basename $0`.current-prompt echo "export PS1=\"$PS1\"" > $TMPFILE echo "source $TMPFILE" Thanks for your assistance :) Zenaan -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/CAOsGNSTSzDxZhEon7VTrKUgH1fj98cQO_Nkpte=4vn7knwz...@mail.gmail.com
Re: using `myscript.sh` to change current env
Am 07. Sep, 2013 schwätzte Zenaan Harkness so: moin moin Zenaan, Rather than all the convolutions of command substitution, how about just using a function that's in your profile or bashrc? $ cat /tmp/bashrc function changeps() { export PS1=': ' } $ . /tmp/bashrc $ changeps : Add arguments to the fx() for your different options :). ciao, der.hans I want to have a script, to change between a few prompts per the arg supplied. This is so I can quickly change from my glorious bells-and-whistles prompt to a plain prompt (eg for cut and paste to debian-user, just "$ " or "# " depending on current user) to a timestamped prompt (when I have some long-running process, and I want to see when it finished) etc. In bash, we cannot run a script plainly, and have that script update the current shell's env. We could source the script with 'source' or '.' command, but this requires a correct location of the script to be entered, which is slow and not ideal. I want to be able to run the script as a command. So I thought, run the script in a subshell, executing the result, like: $ `ps1` The following 3-line script is meant to test exactly this: #!/bin/bash PS1=': ' echo "export PS1=$PS1" Note that in this example, the desired new prompt is a colon followed by a single space. The problem is, when I run this script as `ps1`, I get a changed prompt, but just to colon, not including the space. Does anyone know how I might have a space character included in my new prompt, using this `way` to change my prompt? TIA Zenaan -- # http://www.LuftHans.com/http://www.LuftHans.com/Classes/ # "Science is like sex: sometimes something useful comes out, but # that is not the reason we are doing it." -- Richard Feynman
Re: using `myscript.sh` to change current env
On 9/7/13, Zenaan Harkness wrote: > So I thought, run the script in a subshell, executing the result, like: > $ `ps1` > > The following 3-line script is meant to test exactly this: > > #!/bin/bash > PS1=': ' > echo "export PS1=$PS1" When I change the last line to this: echo "export PS1=\"${PS1}\"" I get: bash: export: `"': not a valid identifier So it appears that my current/parent shell is tokenizing the output of `...` based on the space. I guess, why is it tokenizing on space, yet ignoring the quotes? TIA Zenaan -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/caosgnsrwo-culo3m9ipf5vhcevoixxetybx-ya0ujh-+awu...@mail.gmail.com
using `myscript.sh` to change current env
I want to have a script, to change between a few prompts per the arg supplied. This is so I can quickly change from my glorious bells-and-whistles prompt to a plain prompt (eg for cut and paste to debian-user, just "$ " or "# " depending on current user) to a timestamped prompt (when I have some long-running process, and I want to see when it finished) etc. In bash, we cannot run a script plainly, and have that script update the current shell's env. We could source the script with 'source' or '.' command, but this requires a correct location of the script to be entered, which is slow and not ideal. I want to be able to run the script as a command. So I thought, run the script in a subshell, executing the result, like: $ `ps1` The following 3-line script is meant to test exactly this: #!/bin/bash PS1=': ' echo "export PS1=$PS1" Note that in this example, the desired new prompt is a colon followed by a single space. The problem is, when I run this script as `ps1`, I get a changed prompt, but just to colon, not including the space. Does anyone know how I might have a space character included in my new prompt, using this `way` to change my prompt? TIA Zenaan -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/CAOsGNSQhMnbEjBBecPYBiF4m20HZ6Av_fZE6EV=ofyaqfgd...@mail.gmail.com