bash completion on user input

This is a discussion on bash completion on user input within the Linux Programming forums, part of the Platform Specific Boards category; hi, i'm working on a small tool to convert some files. while the program is running, the user is being ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02:53 PM
  3. vectors and user input
    By Chaplin27 in forum C++ Programming
    Replies: 6
    Last Post: 01-17-2005, 09:23 AM
  4. Nested Structures - User Input
    By shazg2000 in forum C Programming
    Replies: 2
    Last Post: 01-09-2005, 09:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21