Useful tab-completion for .bashrc

I was searching for a tab completion in systemd commands such as:
$ systemct <TAB> (this show all possible parameters/flags) and another <TAB> (show all units and itself commands).
Reading posts here and there I found that the following command in .bashrc:
complete -F or -C command
did the trick, but this is awful and painfull  cause I need to implement it in all commands, such as, pacman, man, sudo, etc. Ok, googling, I found this usefull script you can put in your .bashrc:
# completion.bash
_vault_complete() {
COMPREPLY=()
local word="${COMP_WORDS[COMP_CWORD]}"
local completions="$(vault --cmplt "$word")"
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
complete -f -F _vault_complete vault
This will complete all your commands with infinite posibilities. (This example use command vault, you can use whatever you want)
I put the link (well explained) here because there is a way to do it in zshell for those interested on it.
http://goo.gl/RFwgK
I hope this can be help someone.
Cheers
Maybe would be useful to put this script on the bashrc wiki.
Last edited by JohnnyDeacon (2013-05-21 13:21:21)

firecat53 wrote:
Just wondering if you actually tested this first...from what I read on the link you provided, this script fragment provided completion for the 'vault' command only if I'm understanding it correctly. In order to make this work for any command, you would have to repeat that shell fragment for _each_ command. Not sure what this gets you over just using 'complete -cf <cmd>'.
I think the author was just explaining how to create a bash completion script for an arbitrary command that could be included along with that command. Most software packages have those bash completion scripts already included. This could be used for a command that doesn't include that script already. If that's what you intended with your post it wasn't clear to me :-)
Scott
Edit:  I also just noticed that without even having 'complete -cf systemctl' in my .bashrc, bash is still giving me a list of possible systemctl options when I hit <TAB> after typing systemctl. Ooo, nice! Never noticed that before
complete -cf <cmd> does not complete with flags and parameters.
I have noticed about a script called bash-completion on repos that do completion very well, I'll check it out if it works with all commands.

Similar Messages

  • ZSH tab-completion for pacman

    A long while ago, I found a set of functions for zsh tab-completion for pacman in the Arch mailing list archives. I've improved them recently to make it faster (reading files from /var/lib/pacman instead of calling pacman itself).
    Anyway, you can find my version in the AUR: zsh-pacman
    enjoy!

    shadowhand wrote:
    Been using zsh-pacman for a while, works great, but I'm having some issues with your netcfg completions, stuff like this:
    02:14:14 %] iwconfig [~]
    _arguments:comparguments:208: invalid argument: device[device]
    This is strange i cant reproduce this bug. Any details ?
    Just for informations:
    zsh --version ~
    zsh 4.2.6 (i686-pc-linux-gnu)

  • Is it possible to have a kind of tab completion for dcpromo parameters

    hi friends
    i need to directly type in the following code into cmd in windows server 2008 R2
    is there any trick or 3rd-party Application to make it easier, i mean adding some kind of tab completion here?
    i don't want to user answer file, imagine i haven't created an answer file & so it's not available now. i need directly type in the entire code
    i asked this question in group policy forum & they guide me to post it here
    thanks in advanced

    You can "add" tab completion / intellisense to Powershell cmdlets that don't have it by creating a proxy function that uses dynamic parameters as
    shown in this example.
    I suppose you can do the same by creating a wrapper PS function for dcpromo tool..
    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________
    Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

  • Using Tab Completion

    I am just starting to work with command-line navigation in terminal. They say "tab completion" is a absolute time-saving feature.
    It worked for me the first time, but now it doesn't. At my home folder, I enter cd, then p and press the Tab key. After pressing the tab key a second time, it should display all choices beginning with p. Nothing happens. Any ideas?

    baltwo wrote:
    Hmmm! I have a simple bash shell set up and all I get is the alert sound. Maybe you're using another shell or have something else set that accounts for the discrepancy.
    Nope. I'm using the system default bash. If I try to complete something that isn't there, such as "cd p", I get an alert. If I try something that has possible completions, like "cd P", I get a list of the directories.

  • Tab completion for wget [SOLVED]

    does anyone know if there is a way to type in a partial url with wget and and use tab to present a list of browsable sub-directories of the remote host?  i thought about just using links or ncftp for http and ftp respectively.  thanks
    Last edited by poopship21 (2009-08-03 21:17:20)

    for the sake of accessing repos and things, i guess a text-mode browser is just as good so i am going to stick to that.

  • "Tab Completion" closing console sessions

    Starting this morning I find that pressing the TAB key terminates console sessions. For instance, running KDE as a user if I run "konsole", then su to root - pressing tab will return me to user console and pressing tab again will close konsole app (Session shell exited with signal 11).
    A text console (ctl-alt-f1) will also terminate pressing tab so not an X problem.
    I did a pacman -Suy yesterday and sed, dbus and vte packages were updated but I can't see anything in those. Dodgy keyboard? I don't know much about termcaps so am a bit stuck.
    A nuisance as I use tab completion quite often.
    EDIT: Hmm, rebooted and problem has gone!

    byte wrote:Can you specify somewhere to use a login shell (bash -l)?
    Normally .bashrc gets sourced by .bash_profile, and unless it's a login shell nothing will happen.
    I tried running "bash -l" but the shell I get doesn't have bash completion either : (

  • Emacs tab completion

    Following is my .emacs file:
    (add-to-list 'load-path
    "~/.emacs.d/plugins")
    (require 'color-theme)
    (require 'pymacs)
    (require 'yasnippet-bundle)
    ;; Initialize Rope
    (pymacs-load "ropemacs" "rope-")
    ;; Initialize Python Mode
    (autoload 'python-mode "python-mode.el" "Python mode." t)
    (setq auto-mode-alist (append '(("/*.\.py$" . python-mode)) auto-mode-alist))
    ;; Initialize PHP Mode
    (autoload 'php-mode "php-mode.el" "Php mode." t)
    (setq auto-mode-alist (append '(("/*.\.php[345]?$" . php-mode)) auto-mode-alist))
    ;; Initialize color theme
    (color-theme-initialize)
    (color-theme-charcoal-black)
    My first problem is the tab completion for yasnippet is not working. For example in a python file when I type cl then <tab> it doesnt insert the class snippet.
    Is there a tutorial on how to use ropemacs. Do I need to open a py file so that the rope menu entry show up then only can I open a project. Is there a project browser in rope.

    To my knowledge, yasnippet does not support symbol completion prior to inserting the appropriate template.
    The following might provide functionality similar to what you're after:
    (defun complete-before-yas-expand ()
    "Complete the symbol at point before expanding with yasnippet."
    (interactive)
    (let ((yrd yas/root-directory)
    completions)
    (while yrd
    (when (eq (car (file-attributes
    (expand-file-name (symbol-name major-mode)
    (expand-file-name "text-mode"
    (car yrd)))))
    t)
    (mapc (lambda (file) (unless (or (string-match "^\\." file)
    (member file completions))
    (setq completions (cons file completions))))
    (directory-files
    (expand-file-name (symbol-name major-mode)
    (expand-file-name "text-mode"
    (car yrd))))))
    (setq yrd (cdr yrd)))
    (when (symbol-at-point)
    (let* ((comp (try-completion (symbol-name (symbol-at-point)) completions))
    (manycomps (> (length (all-completions (symbol-name (symbol-at-point)) completions)) 1))
    (input (if manycomps (completing-read "Snippet: " completions nil nil comp)
    comp)))
    (when input
    (delete-backward-char (length (symbol-name (symbol-at-point))))
    (insert input))))
    (yas/expand)))
    (define-key yas/minor-mode-map (kbd "<tab>") 'complete-before-yas-expand)
    Unfortunately, I'm not familiar with pymacs or ropemacs.  For project management, CEDET might be a good place to start looking.
    Last edited by chpln (2009-09-27 02:41:46)

  • PowerShell Script Module PreCache Ignores DefaultCommandPrefix in Manifest - Results in Tab Completion Errors

    Refer to this thread for background...
    https://social.technet.microsoft.com/Forums/windowsserver/en-US/6507710a-5648-4f52-8d46-3bf6c75ac7f3/module-function-name-resolution-issues-with-defaultcommandprefix?forum=winserverpowershell
    The issue is when PowerShell auto loads the meta data into the CommandAnalysis cache it loads the functions defined in a script module (*.psm1) without consideration that a manifest file (*.psd1) may contain a DefaultCommandPrefix declaration. As a result
    if a user attempts to enter a function using tab completion PowerShell will offer the name as defined in the script module which fails to execute (name not recognized). Importing the module will make the correct name with prefix available for tab completion.
    My recommended approach would be to include the DefaultCommandPrefix in the meta data cache during the initial population as a session is instantiated. Also, when a module is loaded explicitly by a user who specifies a -Prefix value the old references containing
    the DefaultCommandPrefix would need to be removed.
    William Busby, PMP

    Hi William,
    yes, that's something you'll either have to do the hard way or live with admin confusion.
    If you're using Sapien's PowerShell Studio as an Editor (hint: Usually a great idea), you can very easily rename a function, even in a multi-file module project, by rightcklicking on the function-name and selecting "rename".
    Alternatively you can do a bulk rename with Powershell:
    Get all functions in your module (Load it and check exportedcommands)
    loop over each function-name
    calculate new name
    search your entire project for all references and replace them.
    Let me see ...
    function Rename-ModulePrefix
    [CmdletBinding()]
    Param (
    [Parameter(Position = 0, Mandatory = $true)]
    [string]
    $ModuleName,
    [Parameter(Position = 1, Mandatory = $true)]
    [string]
    $OldPrefix,
    [Parameter(Position = 2, Mandatory = $true)]
    [string]
    $NewPrefix,
    [Parameter(Position = 3)]
    [string]
    $Path
    # Catch all typos
    Import-Module $ModuleName -ErrorAction 'Stop'
    # Get root path if not manually passed
    if (-not $PSBoundParameters["Path"])
    $Path = (Get-Module $ModuleName).Path
    # Get module files
    $Files = Get-ChildItem -Path $path -Recurse -Include "*.ps1", "*.psm1", "*.psd1"
    # Iterate over each file
    foreach ($file in $Files)
    # Null variable in case you get an empty file somewhere and run this from Win 7
    $data = $null
    # Get Content of file
    $data = Get-Content $file
    # Replace strings
    foreach ($c in (Get-Module $ModuleName).ExportedCommands)
    $newName = $c.Name -replace $OldPrefix, $NewPrefix
    $data = $data | ForEach-Object { $_ -replace $c.Name, $newName }
    # Write back to file
    $data | Set-Content $file
    While I didn't proof it, in theory this should do it (Make a backup before running it :) ).
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • Tab Completion within Terminal

    I'm currently studying the Peachpit book on OSX Support Essentials and have just arrived at the section concerning tab completion in the Terminal. According to the book, if I start from my home folder, then type P, and then press the Tab key, I should get all the choices available to me within the home folder that start with P. I tried this and it worked for me once. Now, however, after restarting, if I do the same thing, I get only one choice - PPCExplain, which is located in Developer/usr/bin/, and not in my home directory. Thinking a preferences must have gotten screwed up, I deleted the preferences for the Terminal, and restarted - still I get this one result and have no explanation of why this command worked as the book said it would and now it doesn't. I'm quite positive I'm starting from my user folder. Any idea what's going on here? Thanks.

    Your terminal is working correctly. In unix-based systems, tab completion is situation-dependent, and for the most part is relative to the root of the drive. If you open a terminal and type P<tab> it will list all commands that are included in your $PATH variable. The $PATH contains file locations (starting from the drive's root) for all the commonly used utilities. To see what the $PATH contains, type the following command in the terminal:
    echo $PATH
    This command will output something like: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    All the paths listed there are targeted when you enter a command. When you press "P<tab>" the system looks for something in these directories that begins with a "P". The terminal assumes "/usr/bin/", "/bin", and the other paths have already been entered, so typing "P" just completes the path from there.
    If you want to run the command "top" which shows all your running processes (similar to activity monitor) is located in the "/usr/bin" directory. Since that directory is in your $PATH, all you have to do is type "top" and press enter. For longer and unique commands you can use tab completion.
    Running "top" as described above is the exact same thing as running "/usr/bin/top". This is the command that is actually run, but having the rest of the file path in the $PATH variable makes it easier than having to type out the whole command.
    As for directories and user files, they're accessed from the root ("/") as well. If you want to access your user folder and show the contents in it via tab completion, start at the root of your drive, as follows:
    /Users/username/<tab>
    Press tab twice to show the available commands or paths. If you want to change your current directory to a new folder, type "cd" before the full file path, as such:
    cd /Users/username/Desktop
    Unix bases everything from the root of the drive as I explained above. However, there are some ways to simplify commands instead of having to type the whole command path before the command itself, or to target a specific file or folder without having to enter the path for the file/folder. These are the period, and the tilde keys: ".", "..", "~".
    To reference the current folder, use the ".", and to reference the parent folder type "..". To reference the user home folder type "~". Other than these options, everything is assumed to be referenced from the root of the drive "/".
    As such, you can change to your home folder these ways:
    cd ~
    cd /Users/username
    These commands perform the same function. The tilde (~) just indicates the current user's home folder, so you dont have to always enter "/Users/username" whenever you want to target something in your home folder.
    Lets take your home folder for example. I'll assume your home's name is "jcoyle".
    If you want to reference your desktop, you are currently trying to do it by pressing "D" and the pressing tab. This wont work. To reference your desktop you'll need to start at the root, or at some of the shortcuts provided by Unix (namely the tilde):
    /Users/jcoyle/Desktop (references from the full path)
    ~/Desktop (references from the user's home folder)
    Continue to press tab to see all the available targets in the desktop folder, and then enter part of the name of one of them and tab-complete it. You can list contents of folders this way.
    Getting back to the periods ("." and ".."), you can reference things relative to your current position. For instance, if you are currently in your Desktop folder, you can change back to your home folder by pressing "cd .." to go up one level. From there you can "cd" into your Movies folder, for example. Alternatively, if you are in your "Desktop" folder you can get to your "Movies" folder directly by typing "cd ../Movies". This tells the computer to go up one level and then target the "Movies" folder that should be there.
    Targeting files and folders like this in the Terminal, however, will not do anything unless the final targeted file is an executable binary file (such as a program). You must perform an action (via a program, ie: one of the commands like "cd") on the referenced path in order to do anything.
    Think about wanting to open TextEdit. You can open it by entering this command:
    /Applications/TextEdit.app/Contents/MacOS/TextEdit
    If you are in the "Applications" directory, you can type the command above, or type:
    ./TextEdit.app/Contents/MacOS/TextEdit
    The period references the current directory ("Applications") and then continues the command from there.
    Say you want to open a file on your desktop called "file.txt" in TextEdit. With the TextEdit program, if you enter the full path of a target file after the command to open the program then the program will try to open that file. For instance, this full command will open the file "file.txt" in the TextEdit program:
    /Applications/TextEdit.app/Contents/MacOS/TextEdit /Users/jcoyle/Desktop/file.txt
    Alternatively, this will work:
    /Applications/TextEdit.app/Contents/MacOS/TextEdit ~/Desktop/file.txt
    (The tilde references the home folder)
    If you are currently in the Applications folder, then this command will also do the same thing:
    ./TextEdit.app/Contents/MacOS/TextEdit ~/Desktop/file.txt
    (The period references the Applications folder itself, so you dont have to type the path before where you currently are located)
    Lastly, if you are in the Applications folder, then this command will also work:
    ../Applications/TextEdit.app/Contents/MacOS/TextEdit ~/Desktop/file.txt
    (the double period references the folder above where you are. In this case it happens to be the root "/" folder, so the full path ends up being what's entered. However, imagine the TextEdit application is in your Desktop folder. In that case if you wanted to open the application (forget about opening files with it for now) you could type these commands (assuming you have just opened the terminal and are currently in your home folder):
    /Users/jcoyle/Desktop/TextEdit.app/Contents/MacOS/TextEdit
    ./Desktop/TextEdit.app/Contents/MacOS/TextEdit
    ~/Desktop/TextEdit.app/Contents/MacOS/TextEdit (in this case the tilde is redundant, since you are already at your home folder)
    ../jcoyle/Desktop/TextEdit.app/Contents/MacOS/TextEdit
    ../../Users/jcoyle/Desktop/TextEdit.app/Contents/MacOS/TextEdit
    The last command invokes two instances of "..", which bring you back two folder levels. In this case, the first would move your reference from "jcoyle" up to the "Users" directory, and from there the second ".." would move you up to the root of the drive "/".
    I hope this long-winded explanation clarifies how paths work in Unix-based systems. Just that by default everything is assumed to be referenced from root, and the included file paths in the $PATH variable is why you see the files from those folders when you just press a letter and tab-complete it.
    It's very logical, but it can be a bit funky to wrap your head around.

  • Open several PDFs in the same Reader window using tabs for each document

    How do I open several PDFs in the same Reader window using tabs for each document?  I'm using Reader 11.0.03 and Windows 7.  

    That would be a nice feature!  Suggest it at https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform - hopefully it will make it into Reader XII.

  • I cannot find all my installed apps on the "use cellular data for" tab on the settings menu.

    I have a new iphone 5s and on the first day I've received it, I updated to IOS 8.0.2.
    Today, I've decided to turn my cellular data on and, in order to consume less data, I thought I would disable some of the apps. However, only a few were available/visible on the "use cellular data for" tab. However, when, with the cellular data turned on, I opened a missing app on the phone, it would start to appear on the list (where it wasn't previously). Also, when I go to the app on the settings menu, it would not have shown the option, "use cellular data" before I've opened the app and now it does. Do I need to turn on every single app before I can select my cellular data preferences? I know people with the same phone and their apps appear all, as expected.
    I don't know if this is a problem of my own carrier but I don't think so, because the people I mentioned earlier have the same carrier.
    Any help would be appreciated.
    Thank you.

    Did you try to reset the phone by holding the sleep and home button for about 10sec, until the Appel logo comes back again? You will not lose data by resetting.
    If this does not work, did you try to switch off Cellular Data, restart the phone and switch it back on again?

  • How can I just disable "navigation toolbar" completely for the App Tabs? I don't want to disable this for other normal tabs.

    How can I just disable "navigation toolbar" completely for the App Tabs? I don't want to disable this for other normal tabs. This is important as otherwise while I am in the app tab, i mistakenly start browsing from that tab and meaning of the app tab is completely lost...

    How can I view my full billing history for the app and music stores without iTunes installed?
    No.
    If my account has been compromised
    If you even think this may have happened, immediately change your password.
    See this -> Apple ID: Changing your password

  • I want to set Firefox to never remember history. When I do this using the tools tab and click okay, it goes right back to "Use Custom Settings for History". I don't want that.

    I know how to manage privacy using the tools tab at the top of the address bar, or so I thought. I want to choose "Never Remember History". When I do that, and click "OK", the next time I check the privacy settings, the history is right back to "Use custom settings for history". I don't want this. Also, I don't want to use autocomplete for forms, but I can't get those settings to stay, either. I basically don't want info. stored on this computer. My system was hacked several months ago, by some joker who named all my system folders a racist slur (I reported it to Norton, and a technician had a look at it). Anyway, I want to keep things as safe as possible. Please allow me to delete all my history when I close Firefox. I don't really like Google, either, because they have a reputation for not respecting people's privacy. I don't like that I didn't have an option to uncheck google's toolbar when I installed Firefox.
    Thank you.

    That is probably OK.<br />
    You may have changed one of the other history or cookie settings.
    If Firefox shows the "Use custom settings for history" setting then that is an indication that at least one of the history and cookie settings are not the default to make you aware that changes were made.

  • My BB9810 refuse to load OS7.1 software on my phone after the download has completed. My phone has freezed/stucked since morning. Pls urgent help/assistant needed as I can not access/use my phone for over 24hrs now.

    My BB9810 refuse to load OS7.1 software on my phone after the download has completed. My phone has freezed/stucked since morning. Pls  urgent help/assistant needed as I can not access/use my phone for over 24hrs now.

    Hi there,
    Use the method described in the link below to get back up and running:
    http://supportforums.blackberry.com/t5/Device-software-for-BlackBerry/How-To-Reload-Your-Operating-S...
    I hope this info helps!
    If you want to thank someone for their comment, do so by clicking the Thumbs Up icon.
    If your issue is resolved, don't forget to click the Solution button on the resolution!

  • Is there a way to turn on auto complete for text that has to be entered repeatedly? I don't want to use a pop up list.

    Is there a way to turn on auto complete for text that is repeated? I don't want to use a pop up list.

    No, not in Number for iOS.

Maybe you are looking for

  • XML Publisher report not printing excel output due to special characters

    Hello, I am trying to create a xml publisher report which should display the output in excel. But the program completes with a warning status and the output is displayed as XML instead of excel, with some errors "An invalid character was found in tex

  • Vendor  & GL Account Balance - department wise

    Hi All, We have a requirement from the client to show the Vendor Account Balance department wise. The scenario is like this. A single Vendor is operated by different sections of the Finance department like Raw Materials Bill passing section, Stores B

  • Turning off 3G on iPhone 5

    Hi everyone so I just got the iphone 5 yesterday & I was wondering why there is no 3G on & off toggle again? it has a 4G LTE toggle which is good cause we don't have 4G LTE yet here but even when I turn it off there is my 3G.  When I am using WiFi at

  • DreamWeaver Extension

    Are extensions included in Creative Cloud?  I am interested in the Dream Weaver Extension for creating a flip book?  Or will I have to download and purchase seperately? Thanks!

  • Airport Questions

    I have my new iMac 24 and airport on my desk, but after quickly running through the setup to get things running, I'm left with a pile of wires that I want to relocate to a desk shelf below the desk. This will involve relocating my airport extreme, ex