0

When writing python code (using gvim) I often keep complex command line commands for test cases saved in my docstrings. A common time-wasting error I make is copying the entire line from the python file and pasting it into the terminal.

For an example one of my functions looks like this

@profile
def incremental_test(ibs, qaid_list, daid_list=None):
    """
    Plots the scores/ranks of correct matches while varying the size of the
    database.

    Args:
        ibs       (list) : IBEISController object
        qaid_list (list) : list of annotation-ids to query

    CommandLine:
        python dev.py -t inc --db PZ_MTEST --qaid 1:30:3 --cmd

        python dev.py --db PZ_MTEST --allgt --cmd

        python dev.py --db PZ_MTEST --allgt -t inc

        python dev.py -t inc --db PZ_MTEST --qaid 1:30:3 --cmd

        python dev.py -t inc --db PZ_Master0
        python dev.py -t inc --db GZ_ALL --ninit 100 --noqcache

    Example:
        >>> from ibeis.all_imports import *  # NOQA
        >>> ibs = ibeis.opendb('PZ_MTEST')
        >>> qaid_list = ibs.get_valid_aids()
        >>> daid_list = None
    """
    from ibeis.model.hots import automated_matcher
    ibs1 = ibs
    num_initial = ut.get_argval('--ninit', type_=int, default=0)
    return automated_matcher.incremental_test(ibs1, num_initial)

And I want to copy one of the various commands into the terminal to test it.

Initially when I copy and paste one of these lines works fine, but if I change code and want to run the test again I find myself pressing the up arrow to get to the previous command in my history. But because the command had leading whitespace I get some other command. What makes this worse is that often the previous command is very similar; maybe I had added a --verbose flag or something, so I don't always catch it right away.

Currently my workaround is that I have to be careful to copy the command from the start of the first non whitespace character or I have to repaste the command. Both of these options break my coding rhythm and I often find myself wanting for a better solution.

With this modivating example my question is:

Is there is a way to configure the gnome-terminal such that when you press up-arrow it gives you the last command even if it has leading whitespace.

I guess an alternative workaround would be for ctrl+shift+c in vim to copy the line to the clipboard but lstrip the whitespace, but I would prefer a terminal hack.

3

That's caused by the ignorespace value in $HISTCONTROL. From man bash:

HISTCONTROL

A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list.

It could be caused by the HISTIGNORE variable, though that usually contains commands to skip.

Just reconfigure your shell history in ~/.bashrc by setting different defaults, e.g.

HISTIGNORE=ignoredups
  • Or possibly HISTIGNORE? – Daniel Beck Dec 15 '14 at 16:10
  • @DanielBeck: Thanks, I was just editing that in :-) Less likely though, right? – Ingo Karkat Dec 15 '14 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.