Results 1 to 5 of 5

Thread: Python get terminal user prompt

  1. #1
    Join Date
    Sep 2013
    Beans
    9

    Wink Python get terminal user prompt

    Hey Everybody,

    I'm trying to make a python script of the xkcd "Make me a Sandwich Comic". I need a way for python to be able to detect and replicate the user's prompt (User@Ubuntu:~$) at the time they run the script. So, if the user has cd'd into /dir/ect/ory/, their prompt will be "User@Ubuntu~/dir/ect/ory/:~$" . I need to be able to grab that in python and output it at the beginning of the line, so it just looks like another terminal line. This assumes the user runs the script using the command line, but if they just click on it, it should just output "User@Ubuntu:~$" in a new terminal.

    Thanks!
    evamvid

  2. #2
    Join Date
    Sep 2013
    Beans
    9

    Re: Python get terminal user prompt

    Also, I need help closing the terminal window after the script finishes, so it doesn't just leave it lying around.

    Thanks!

  3. #3
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,165
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Python get terminal user prompt

    https://help.ubuntu.com/community/CustomizingBashPrompt

    Good luck

    (didn't a find any way to obtain the current prompt in a file.... but I have missed something)

  4. #4
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,294
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Python get terminal user prompt

    And why exactly do you want to do this in Python? Just do it in Bash...
    「明後日の夕方には帰ってるからね。」


  5. #5
    Join Date
    Sep 2013
    Beans
    9

    Re: Python get terminal user prompt

    I thought it would be a fun Python exercise.

    I am planning to learn bash, but I wanted to do this one in python.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •