Can Bash achieve this kind of completion ?

I'm a bash user, who's been checking out a few zsh configs lately, to see what it's made of.
And for the most part, I haven't seen many things that I couldn't live without, except for this nifty completion thingy :
This config provides a completion mechanism, that displays little docstrings explaining a bin's options, which is so damn useful.
When you type something like :
➜ ~ grep -[TAB]
You get :
--after-context -A -- specify lines of trailing context
--basic-regexp -G -- use basic regular expression
--before-context -B -- specify lines of leading context
--binary-files -- specify type to assume for binary files
--byte-offset -b -- print the byte offset with output lines
--colour --color -- distinguish matching string
--context -C -- specify lines of context
--count -c -- only print a count of matching lines
--devices -D -- specify handling of devices, FIFOs and sockets
--directories -d -- specify handling of directories
--exclude -- skip files matching specified pattern
--exclude-from -- skip files matching pattern in specified file
--extended-regexp -E -- use extended regular expression
--file -f -- specify pattern file
--files-with-matches -l -- output matching files' names only
--files-without-match -L -- output non-matching files' names only
--fixed-strings -F -- use literal strings
--help -- display help
-I -- process binary files as if non-matching
--ignore-case -y -i -- case-insensitive
--include -- examine files matching specified pattern
--invert-match -v -- select non-matching lines
--label -- provide filename to print for stdin
--line-buffered -- flush output on every line
--line-number -n -- prefix output with line numbers
--line-regexp -x -- force pattern to match only whole lines
--max-count -m -- stop after specified no of matches
--mmap -- memory map input
--no-filename -h -- suppress printing of filenames
--no-messages -s -- suppress messages about unreadable
--null -Z -- print 0 byte after FILE name
--only-matching -o -- show only matching part of line
--perl-regexp -P -- use perl regular expression
--recursive -R -r -- recurse subdirectories
--regexp -e -- specify pattern
--silent --quiet -q -- suppress normal output
--text -a -- process binary file as if it were text
--version -V -- display version info
--with-filename -H -- print filename with each match
--word-regexp -w -- force pattern to match only whole words
That's just awesome, and I really lust for this feature now...
I haven't made the jump to zsh, as I'd rather stick with stuff that's available on virtually every machine I use (zsh users don't flame, I know it's basically better than bash, I'd just rather have portability over functionality most of the time).
So any bash gurus know if this can be done ?

I've been looking for that also... I think there is no "good" way to do it, but I use an ugly trick to get something similar.
For example, for the kill command I use the following "complete" rule
_kill ()
local cur aux
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $( compgen -W '$( ps -U$USER -o pid )' -- "$cur" ))
if [ $COMP_TYPE -eq 63 ]; then
echo ""
ps -lU$USER |\
awk -v cur=$cur '{if (index($4,cur)==1 || NR==1)\
print "\033[1m" $4 "\033[0m" "\t" $5 "\t" $14}'
fi
return 0
complete -F _kill kill
which gives something like this
olvar:~$ kill 10[TAB][TAB]
PID PPID CMD
10397 1921 urxvt
10405 10397 bash
10397 10405
olvar:~$ kill 10
Of course this is ugly, it uses ps twice and sorts the results twice, not to mention that you have the matches repeated in the screen,
but I haven't found anything better nor how to hide the $COMPREPLY array.
For grep i think I'd do something like
_grep ()
local cur
cur=${COMP_WORDS[COMP_CWORD]}
if [[ "$cur" = -* && $COMP_TYPE -eq 63 ]]; then
echo ""
$1 --help 2>&1
echo ""
fi
_longopt $@
complete -o filenames -F _grep grep
Probably you would like to parse the output better than just the "$1 --help 2>&1" I wrote.
Anyone else with a better suggestion?
Last edited by olvar (2010-03-11 20:32:52)

Similar Messages

  • I want to delete my current exchange account. How can I achieve this and not lose stored information such as contacts, photos etc. please help. Thank you.

    I want to delete my current exchange account and replace it with my new one. How can I achieve this and not lose my contacts, photos, etc associated with this account? Please help..
    Thank you,

    Bad idea.
    What information do you want to share, exactly?  You can share contacts, reminders, and calendars with other iCloud users without the need for both of you to use the same iCloud account.  You can authorize both phones to use apps purchased under the same Apple ID without sharing an iCloud account.
    Sharing an iCloud account is a bad idea in general. There is too much opportunity for someone to damage or delete data that will affect both.

  • How can I perform this kind of range join query using DPL?

    How can I perform this kind of range join query using DPL?
    SELECT * from t where 1<=t.a<=2 and 3<=t.b<=5
    In this pdf : http://www.oracle.com/technology/products/berkeley-db/pdf/performing%20queries%20in%20oracle%20berkeley%20db%20java%20edition.pdf,
    It shows how to perform "Two equality-conditions query on a single primary database" just like SELECT * FROM tab WHERE col1 = A AND col2 = B using entity join class, but it does not give a solution about the range join query.

    I'm sorry, I think I've misled you. I suggested that you perform two queries and then take the intersection of the results. You could do this, but the solution to your query is much simpler. I'll correct my previous message.
    Your query is very simple to implement. You should perform the first part of query to get a cursor on the index for 'a' for the "1<=t.a<=2" part. Then simply iterate over that cursor, and process the entities where the "3<=t.b<=5" expression is true. You don't need a second index (on 'b') or another cursor.
    This is called "filtering" because you're iterating through entities that you obtain from one index, and selecting some entities for processing and discarding others. The white paper you mentioned has an example of filtering in combination with the use of an index.
    An alternative is to reverse the procedure above: use the index for 'b' to get a cursor for the "3<=t.b<=5" part of the query, then iterate and filter the results based on the "1<=t.a<=2" expression.
    If you're concerned about efficiency, you can choose the index (i.e., choose which of these two alternatives to implement) based on which part of the query you believe will return the smallest number of results. The less entities read, the faster the query.
    Contrary to what I said earlier, taking the intersection of two queries that are ANDed doesn't make sense -- filtering is the better solution. However, taking the union of two queries does make sense, when the queries are ORed. Sorry for the confusion.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Sorry - Could you please help me how can I achieve this Search help ?

    I am creating search help for the profit_center field,
    For the search help :
    The scenario is I have three Z-tables.
    Example: The Data in tables are as shown below ( where F1, F2 are the fields ).
    Ztable1
    F1
    A
    B
    C
    D
    Ztable2
    F1 F2
    A 1
    A 2
    B 112
    B 113
    C 34
    D 43
    D 55
    D 87
    Ztable3
    PRCTR F1 F2
    123 A 1
    124 A 2
    123 B 112
    124 B 113
    125 C 34
    123 D 43
    124 D 43
    125 D 43
    I need to create search help (Search Help is similar to Collective Search Help) for the field PRCTR of table Ztable3 like as below.
    By pressing F4 on the field, a pop up should appear which should contains text labels& text fields on TAB-Screen ( A, B, C , D as shown below as text lables )against which text fields should appear.
    TAB-Screen :
    A ____________
    B ____________
    C ____________
    D ____________
    If F4 is pressed on I/O field (text fields) against A in the above TAB-Screen, Corresponding values ztable2-F2 of A from ztable2 ( = 1, 2 ) should appear as F4 help.
    so that user can select ...
    Is it possible to acieve this ? It would be a great help ....How can I achieve this ?
    Finally based on above user selections say
    A ____________
    B ____________
    C ____________
    D ____________
    corresponding prctr values should be collected.

    <b>You can acheive   this .... first by creating the search help exit    ... by  creating the maintaince  view   then   using it in the   Creation of the search help </b> ...
    see the link for attaching the view   to the serach help .
    <a href="http://">http://www.sapdevelopment.co.uk/dictionary/shelp/shelp_elementary.htm</a>
    reward  points if it is usefull...
    Girish

  • How can i design this kind of chart ?

    How can I create this kind of pie chart.

    After you enable dashed line, go the right and make sure the second icon is down. Enable the second icon for cap. Enter the 3 values I have shown, and then adjust to your liking

  • Can we achieve this cosmotic red from a JavaScript?

    Hello
    If I set a field as REQUIRED (pic. 1) I will get a bold thick red border aroud my field (pic. 2), well.
    Setting a field as REQUIRED - Pic. 1
    Getting below red bold thick border Pic. - 2
    Pls. suggest us can we achieve the same effect / cosmotic effect with a JavaScript, if so, pls. help me by giving the JS code snippet
    We want just cosmotic effect (no need of data validations), meaning, just a  thick red bold border around the just field (not including caption), pls. let us know the JS to get this
    Thank you

    Hi, to be able to set the text fields like so you should use the three line below:
    TextField1.ui.textEdit.border.edge.color.value = "255,0,6";        //Change the color of the borders
    TextField1.ui.textEdit.border.edge.stroke = "solid";                    //Change the look of the borders
    TextField1.ui.textEdit.border.edge.thickness = "2pt";                 //Change the border's width
    Hope this helps!

  • Particle effect -how to achieve this kind of effect exactly

    Hello   please help me to achieve this type of flickering particle effect.  how to achieve this in After effect  which is shown at 0.8 sec to 0.11  in the attached link video. http://www.istockphoto.com/stock-video-2682258-hearts.php

    I can't give you the exact settings but you could use Trapcode Particular with a custom particle or CC Particle world. Just turn gravity to 0 and set up a custom particle.
    Your particle layer will be behind the spinning hearts layer. This should get you going in the right direction.

  • Need to open .fcp  project from FCP7 in FCPX 10.0.3. How can I achieve this without exporting the original from FCP7 to a QT movie? I need the original timeline in FCPX.

    I have been working on a scholarship short film for a couple of months now (am a senior in high school) and have been using my school's Mac Pros with OSX 10.7 and FCP7 to edit it. Yesterday I bought a Macbook Pro and got FCPX, and am having trouble moving everything over (the computers at school are going to be wiped for the end of the year soon and I must continue to edit it on my MacBook). The project file "MattsShort.fcp" from FCP7 at school isn't even being recognized as a project file by the newest version of FCPX, so obviously I cannot open it and get to work connecting the media. How can I open this file in FCPX? Excluding exporting the project at school to a quicktime movie, I need to be able to further edit the timeline.

    Cool, thanks! I was able to import the timeline into FCPX but all of the files are offline, even though I imported the same exact clips that were in the original FCP7 project, into the same 'event' that I have the new FCPX timeline in. I believe the problem lies in that FCPX imported the clips and named them after the date and time they were created, rather than the "Clip #XXX" that FCP7 assigned to the timeline. Does this sound correct? And if so, is the only way to solve this problem to go back to FCP7 and rename all of the clips assigned to the timeline to the names FCPX gave them? I really hope there is a simpler solution but given all of the work it takes to even import a FCP7 project into FCPX, I wouldn't be surprised if that was the only solution.
    A little more info: When I use 7toX to convert the XML file, it says that my media will be offline.
    EDIT: I just watched a youtube video that explained that 7toX brings over the required media.....why isn't it doing that for me? I am on two different computers if I hadn't already said.
    Message was edited by: MattMadoni

  • When I start ffox I want the same 2 tabs to open EVERY time no matter what sites I have visited in previos session - can I achieve this

    when I start ffox I want the same 2 tabs to open EVERY time no matter what sites I have visited in previos session - can I achieve this

    In the home page setting you need to use a pipe (|) symbol as separator.
    See [[How to set the home page]]
    You can also create or modify a Firefox desktop shortcut and add the two URLs to the target field of that shortcut.
    In that case you need to separate the URLs with a space.
    "C:\Program Files\Mozilla Firefox\firefox.exe" http://site1.com http://site2.com

  • How can i get this kind of background

    Hello,
    I downloaded some brushes in here : http://differentxdreamz.deviantart.com/art/Abstract-Design-Brushes-119627540.
    I just want to do the same background with those brushes but i could'nt. I've made a lot of gradient colors but it's not like this picture.
    Some descriptions of the differents steps would be very useful for me.
    Also, how can i get this mix of colors in the bottom of this picture : http://www.shutterstock.com/pic.mhtml?id=56261755
    Thanks

    Hi,
    To get blurred colors you can use a bluring technique. Start off by painting large spots of color on your image.
    Go to FIlter > Blur > Gaussian Blur:
    Then, change the intensity of the blur to your liking
    As far as the other image, that seems a little more complicated and requires some more steps.
    Here's the tutorial for that image:
    http://differentxdreamz.deviantart.com/art/Abstract-Aura-Tutorial-123825904
    Hope this helps!
    Julia

  • How can I avoid this kind of pigment? (What really causes it?)

    I have clip that works great with all kinds of effects on it, except brightness/contrast (both of them used separately as well). The second I render the clip with those effects, my clip becomes "choppy". It's weird, cause with other color effects (including luma) it doesn't react like this. It seems to be that red tones are more susceptible for it as well.
    Why do this happen and how do I deal with this? I'm interested in the color, not the image btw. What other way can I get a strong contrast-darkness effect.

    I must also add, maybe the crucial part. 636 x 480 square pixel 1.0 are the settings for the clip, and it reacts this way when I copy and paste it (and render) into 720 x 576 16:9 D1 widescreen (1.45).
    So how can I get it to fit the widescreen? I've tried to create a new project with it and save it as a 720 x 576 but with the same result, but when I render, I get the same result.
    Thx

  • My Ip5 got stocked on "searching..." For my carrier. I already removed the SIM but it doesnt stop searching. How can i troubleshoot this kind of problem?

    How can I troubleshoot my iphone5 if it got stocked searching for my carrie?. I already tried removing the SIM card but it doesnt stop searching. I also tried using other SIM but still same result.

    Try this: press F10 or tap the Alt key to display the menu bar temporarily, then
    View > Toolbars > Menu Bar
    If that doesn't work, you could reset your toolbars to factory default using Firefox's Safe Mode. First, make a backup of your computer for safekeeping. To back up Firefox, see [https://support.mozilla.com/en-US/kb/Backing+up+your+information Backing up your information].
    Next, start Firefox in Firefox
    [http://support.mozilla.com/kb/Safe+Mode Safe Mode], and check only the box to reset toolbars. Be careful not to "reset" anything else if you didn't back up.
    Hope this helps.

  • HOW CAN WE ACHIEVE THIS REPORT IN OBIEE10G

    THIS IS DATABASE TABLE
    APPLICATION_NAME     APPLICATION_STATUS
    ACNFS                              0.1
    ACNFS                              0.1
    ACNFS                              0.1
    ACNFS                              0.1
    ACNFS                             -0.9
    BDN                                   0.1
    BDN                                   0.1         
    BDN                                   0.1
    BDN                                   0.1
    BDN                                   -0.9
    BDN                                    -0.9
    BDN                                   -0.9
    C2C                                   0.1
    C2C                                   0.1
    C2C                                   -0.9
    C2C                                    -0.9
    FINALLY I WANT MY REPORT IS IN THIS FORMAT IN OBIEE10G
    APPLICATION_NAME      TOTALCOUNT     PASSEDCOUNT      FAILEDCOUNT      %AVAILABILITY
    ACNFS                              5                         4                              1                         80%
    BDN                                   7                         4                              3                         56%
    C2C                                    4                        2                              2                          50%
    PLS SUGGEST ME HOW TO DO THIS PROCESS IN OBIEE 10G  WITH LOGICS
    THANKS&REGARDS
    SUDHEER              

    Hi All, I have a scenario to implement.Need urgent help. I have relational source which has below fields. ID,Account,AccountType,Balance1,1001,GL,46567.901,1002,SL,56889.971,1003,Equity,45543.9081,1004,GL,89.541,1005,SL,-56889.971,1006,Equity,-45543.9081,1007,SL,-42777.45  Here my first requiremnt is to check if the balance value for entire file is 0 and if balance amount for each AccoutType is 0 , if both condtionn satifies the flow will go , else load will fail. I tried in below approach. SQ >> Expression >> Aggregator  In aggregaor i have first calculated sum(balance) for entire file by group by on ID column in an aggregator , and keep actual data in expression transformation. Then i took an expression to connect actual data with the sum(balance) , since i need to perform further calculation.I tried connecting expression and aggregator , but it is not allowing me to connect the posrts. And if i am using a joiner , then wrong data is loading to target. It is joining each result of aggregator with actual ports in expression.   I am not sure how to handle this scenario, so that we can just calculate sum of entire file and sum on basis of account type , is both sum are 0 then load the target , else fail.

  • How can I achieve this with less code or faster?

    Hi Folks,
    I have 2 database tables, 'products' and 'products_staging'.
    Every day, the 'products_staging' table is updated with a fresh
    batch of products (which are imported from xml files in a seperate
    process using Navicat software). I need to somehow compare this
    database with the 'products' database to look for specific changes
    - i.e changes in price, deleted products, or new products. As some
    of the fields in the 'products' database are manually altered, such
    as the product name, I cannot do a straight sync with them.
    Therefore, I use the only field that will remain unchanged as the
    comparison field.
    The somewhat crude method I have come up with is to loop
    through the 'products_staging' table, looking for that specific
    field against the 'products' table. If it finds it, it then checks
    for a change in the price field (i.e has the price of that product
    changed). If there is a change, the 'products' table is updated.
    Likewise, if it's not found, it's treated as a new product and
    inserted as such and so on. At the end of the loop, the record is
    deleted from the 'products_staging' table - therefore at the end of
    the process, the table is empty ready for the next import the
    following day.
    At the moment, the database handles around 300,000 rows - but
    at some point I'm likely to be dealing with many more than that.
    It's working as it is, but taking a considerable time to do so -
    around 4 hours to go through the lot.
    Any suggestions on a better way of accomplishing this? My
    existing crude code is pasted below (the use of maxrows and the
    redirect is to prevent time-outs - parse2.cfm is virtually
    identical to this);

    Firstly, if possible, get the DBs to talk to each other
    without involving
    CF. That will just be slowing things down. CF's for
    generating HTML
    pages, and whilst it CAN interact with databases, it's not
    the best tool
    for the job.
    If that's not possible, use CF as a bridge between them, but
    only to bulk
    insert all the staging data into a temporary table (either
    literally a
    temporary table, or a permanent one used for holding data
    temporarily ;-)
    on the production DB, and then use a DB procedure to process
    all the data,
    again using only the DB server to do so.
    Lastly, if you MUST use CF to do the data manipulation, then
    minimise your
    hits to the DB. Instead of doing single hits to the
    production DB in your
    prodconnect query, get ALL the data you're likely to need for
    updates in
    one hit, then use CF to generate a payload for a bulk update;
    similarly any
    missing data from production can be inferred from that the
    difference
    between the staging and update data, and that can be used as
    your source of
    payload for a bulk insert.
    As a rule of thumb, if I find myself needing to perform
    single-row queries
    within a loop of another query, I start thinking I'm doing
    something wrong.
    Oh, yeah: when dealing with large amounts of queries like
    that, ALWAYS use
    <cfqueryparam> tags instead of static SQL strings.
    Every non-parameterised
    query you pass to the DB engine will need to be compiled
    first, and then
    it's also cached. Which slows you down, and eats memory on
    the DB server.
    This will leave the problem that you're not going to be
    generating your
    report as you go. However I imagine that's a "nice to have"
    compared to
    ensuring the thing actually works. You can generate your
    report
    separately, after the data processing has been done. I'm
    fairly certain
    you would be able to coerce a log out of the DB server,
    somehow, anyway.
    Adam

  • We have 2 session in workflow if 1st session got failed-still 2nd session has to execute and workflow should go to suspended mode.How can we achieve this?

    Thanks Veeru In this case workflow will go to Failed state but I want it in Suspended mode. Can you please help over here/

    HI Mounika, At session level you have option fail parent if task fails. Failing  Parent Workflow or Worklet #You can choose  to fail the  workflow or worklet if a task fails or does not run. The workflow or worklet that  contains the task instance is called the parent. A task might not run when the input condition for  the task evaluates to False.#To fail the parent workflow or  worklet if the task fails, double-click the task and select the Fail Parent If This Task  Fails option in the  General tab. When you select this option and a task fails, it does not  prevent the other tasks in the workflow or worklet from running. Instead, the  Integration Service marks the status of the workflow or worklet as failed. If you have a  session nested within multiple worklets, you must select the Fail Parent If This Task  Fails option for  each worklet instance to see the failure at the workflow level. #To fail the parent workflow or  worklet if the task does not run, double-click the task and select the Fail Parent If This Task  Does Not Run option in the General tab. When you choose this option, the  Integration Service fails the parent workflow if a task did not run.  This will help you. Regards,Veeru

Maybe you are looking for

  • Still not update my lumia 620

    Hi gud even I done with ur prosess like using Lumia updater itz juz update extra n info... Not update my device...... Now what the next prosess which will do update my Lumia 620.... :'(:'(

  • Scrubbing videos in iPhoto 9.6?

    I upgraded to iPhoto 9.6 in Yosemite and now I can't scrub my videos.  I used to be able to run my finger across the track-pad while the video was in Pause to slow-mo it forward or backwards.  Does anyone know how this is done in the new iPhoto 9.6? 

  • I have photoshop and muse but need video editing  which plan would be best for me.

    I have photoshop and muse but need video editing  which plan would be best for me.

  • BlackBerry-8800 Cannot Install Third-party softwares

    Hi ... can anyone help me how to be able to change all settings (including password prompts), and install Third Party Applications I am unable to make changes to the settings or install Third Party Applications. I have a Blackberry that was previousl

  • Why can I not load ANY video on my iPhone5 over wifi?

    It all happened at random, one day(about a week ago) videos over YouTube or anything else would not seem to load. I know it can't be my wifi because the internet is fine, and whenever I go to the YouTube app EVERYTHING loads perfectly normal such as