Skip to main content

Curses List Picker

Project description

CURSES LIST PICKER

img

Pick items from a list with a nice TUI, & comfy Vi keybindings.

INSTALLATION

pip install cpick

CLI USAGE

USAGE: cpick:

[-h]        [--help]
[-l LIMIT]  [--limit LIMIT]
[-n]        [--numbers]
[-H HEADER] [--header HEADER]
[-F FOOTER] [--footer FOOTER]
[ITEMS]     [items ...]

Curses List Picker.

Positional Arguments:
  [ITEMS]                : Items for the picker.

Optional Arguments:
  -h, --help             : Show this help message and exit.
  -l, --limit [LIMIT]    : Limit number of picks.
  -n, --numbers          : Show line numbers.
  -H, --header [HEADER]  : A string to use as a header.
  -F, --footer [FOOTER]  : A string to use as a footer.

PYTHON USAGE

Example using all available arguments

import cpick

# keyword argument dictionary
kwargs = {
	# list to feed into the picker
	'items': ['a', 'list', 'of', 'items'],
	# only allow five items to be picked, defaults to sys.maxsize
	'limit': 5,
	# turn line numbering on
	'numbers': True,
	# defaults to 'PICK ITEMS FROM THIS LIST'
	'header': 'My Awesome Custom Header',
	# defaults to 'Press [?] to view keybindings'
	'footer': 'My Awesome Custom Footer',
}

# splat args using ** to unpack kwargs dictionary
picked = cpick.pick(**kwargs)

# print picked list
print(*picked, sep=", ")
# output if all items picked: a, list, of, items

Example using only a list

# pass in only mandatory arg - a list.
picked = cpick.pick(items=['just', 'a', 'list'])
print(*picked, sep=", ")
# output if all items picked: just, a, list

KEYBINDINGS

KEY ACTION
k,UP Move up one line
j,DOWN Move down one line
g,HOME Jump to first line
G,END Jump to last line
f,PGDN Jump down a page of lines
b,PGUP Jump up a page of lines
# Jump to line number
/ Find items via wildcards, regex or range
n Jump to next search result
p Jump to previous search result
CTRL-n Jump to next pick
CTRL-p Jump to previous pick
r,F5 Reset search results and picks
z,CTRL-l Recenter current line on screen
RET Pick an item
; Pick via wildcards, regex or range
u Undo the last pick
U Undo the last pick and move to it's line
t Toggle an item
SPC Toggle item and go down a line
CTRL-SPC Toggle item and go up a line
a Toggle all items
: Toggle via wildcards, regex or range
v View picked items
?,F1 View this help page
w,CTRL-s Save picks to a file
q,ESC Quit and display all marked paths

NOTES

Picking[;], toggling [:], and searching[/] is supported via the following methods:

  • Unix Style Wildcards.

  • Regular Expressions.

  • Matching a complete string (ie. not substrings - use wildcards for this.)

  • Specifying the line number of an item.

  • Specifying a range of line numbers in the following forms:

    PROMPT ACTION
    x..y Match line numbers between x and y
    x-y Match line numbers between x and y
    x.. Match line numbers from x until the end of the list
    ..y Match line numbers from beginning of list until y
    x- Match line numbers from x until the end of the list
    -y Match line numbers from beginning of list until y

These can also be combined. You can enter multiple patterns, ranges and strings at one Pick:, Toggle: or Find: prompt.

However, be aware, that when toggling - if patterns, ranges or strings are entered that match the same items, they will cancel each other out.

For example, if you entered 1..10 ^[A-Z][a-z]+$ on a list where the first 10 items were capitalised words, nothing would be picked.

The 1..10 would pick the first ten items, and then the ^[A-Z][a-z]+$ would unpick them, since they call the toggle method consecutively.

If you do not want this (you probably don't..) - use the Pick: prompt instead.

EXAMPLES

Pick a number from 1 to 100, using custom header/footer and limiting picks to 5.

cpick --header "My header" --footer "My footer" --limit 5 {1..100}

Pick 5 random words from the dictionary, using the default header/footer.

cpick --limit 5 $(shuf -n 100 /usr/share/dict/words)

Pick an unlimited number of paths from the current directory.

cpick $(ls)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpick-0.1.3.tar.gz (12.3 kB view details)

Uploaded Source

File details

Details for the file cpick-0.1.3.tar.gz.

File metadata

  • Download URL: cpick-0.1.3.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for cpick-0.1.3.tar.gz
Algorithm Hash digest
SHA256 cd0a14f837efda9553a636597e2bd9c6da85e55bc5376e5ca4a1d400e40e9656
MD5 54cf3fb067481105479b4565197d398b
BLAKE2b-256 9d0072cff6c3f6292814d96ef7d1b691cf4be5ec881ce403ff6cf56970d39546

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page