Thread: bash completion on user input

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    23

    bash completion on user input

    hi,

    i'm working on a small tool to convert some files. while the program is
    running, the user is being asked to enter some file-paths.
    i'm actually doing this with a cin, but it would be - obviously - more
    comfortable if the user could use the bash-completion. is there a
    way to implement this?

    thanks,

    toby

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yes, link your code with the readline library.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    23
    thanks! well... and that's it then? bash-completion on cin?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, you would need to use the readline function, defined in the readline library. cin is not changed by this.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    23
    yepp, it works, thanks a lot!!

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by t0bias View Post
    yepp, it works, thanks a lot!!
    Be careful though -- readline doesn't know that cin exists. They both do some sort of buffering. So they can step on each other's toes.

    Once you've decided to use readline, you should use it for ALL input. Don't use cin at all.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The same goes for mixing std::cin and std::getline

    Mixing any combination of input styles usually results in coming unstuck at some point. Pick one at stick with it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  2. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  3. vectors and user input
    By Chaplin27 in forum C++ Programming
    Replies: 6
    Last Post: 01-17-2005, 10:23 AM
  4. Nested Structures - User Input
    By shazg2000 in forum C Programming
    Replies: 2
    Last Post: 01-09-2005, 10:53 AM