From 093921cb9abf02c080e138c5a255e77a55aceca3 Mon Sep 17 00:00:00 2001 From: Robert Ricci Date: Mon, 4 Jun 2018 14:25:38 -0600 Subject: [PATCH] Add support for sha1 hashes to the hint kitten This is specifically intended for git commit hashes, so it allows for hashes as short as 7 characters (git's default length for abbreviated hashes) up to the full 40 characters --- kittens/hints/main.py | 6 ++++-- kitty/kitty.conf | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 752de87fc..b12e776c1 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -244,6 +244,8 @@ def functions_for(args): post_processors.extend((brackets, quotes)) elif args.type == 'line': pattern = '(?m)^\\s*(.+)[\\s\0]*$' + elif args.type == 'sha1': + pattern = '[0-9a-f]{7,40}' elif args.type == 'word': chars = args.word_characters if chars is None: @@ -313,7 +315,7 @@ terminal window instead. A value of :file:`@` will copy the match to the clipboa --type default=url -choices=url,regex,path,line,word +choices=url,regex,path,line,sha1,word The type of text to search for. @@ -331,7 +333,7 @@ Comma separated list of recognized URL prefixes. --word-characters -Characters to consider as part of a word. In addition, all characters marked as +Csha1,haracters to consider as part of a word. In addition, all characters marked as alpha-numeric in the unicode database will be considered as word characters. Defaults to the select_by_word_characters setting from kitty.conf. diff --git a/kitty/kitty.conf b/kitty/kitty.conf index fb3a104b0..d2592202c 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -490,6 +490,10 @@ map kitty_mod+e kitten hints # run git commands on a filename output from a previous git command. map kitty_mod+p>f kitten hints --type path --program - +# Select something that looks like a SHA1 hash and insert it into the terminal. +# Useful with git, which uses sha1 hashes to identify commits +map kitty_mod+p>s kitten hints --type sha1 --program - + # Select a path/filename and open it with the default open program. map kitty_mod+p>shift+f kitten hints --type path