File: cmd_grep.py

package info (click to toggle)
python-keep 2.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 184 kB
  • sloc: python: 542; sh: 25; makefile: 3
file content (17 lines) | stat: -rw-r--r-- 558 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import click
from keep import cli, utils


@click.command('grep', short_help='Searches for a saved command.')
@click.argument('pattern')
@cli.pass_context
def cli(ctx, pattern):
    """Searches for a saved command."""
    matches = utils.grep_commands(pattern)
    if matches:
        for cmd, desc in matches:
            click.secho("$ {} :: {}".format(cmd, desc), fg='green')
    elif matches == []:
        click.echo('No saved commands matches the pattern {}'.format(pattern))
    else:
        click.echo('No commands to show. Add one by `keep new`.')