else
This commit is contained in:
parent
24dcbfb658
commit
53fcf8acd4
5 changed files with 10 additions and 132 deletions
|
@ -817,7 +817,7 @@ words=['Aaberg',
|
|||
'Amy',
|
||||
'Amyas',
|
||||
'Amye',
|
||||
'Am‚lie',
|
||||
'Amelie',
|
||||
'An',
|
||||
'Ana',
|
||||
'Anabal',
|
||||
|
|
|
@ -134,7 +134,7 @@ function create_odi_div(url)
|
|||
{
|
||||
var div = null;
|
||||
var paramless_url = url.split("?")[0];
|
||||
var basename = get_basename(url);
|
||||
var basename = decodeURI(get_basename(url));
|
||||
|
||||
if (paramless_url.match(IMAGE_TYPES))
|
||||
{
|
||||
|
@ -167,7 +167,7 @@ function create_odi_div(url)
|
|||
var load_button = document.createElement("button");
|
||||
load_button.className = "load_button";
|
||||
load_button.odi_div = div;
|
||||
load_button.innerHTML = decodeURIComponent(unescape(basename));
|
||||
load_button.innerText = basename;
|
||||
load_button.onclick = function()
|
||||
{
|
||||
this.parentElement.removeChild(this);
|
||||
|
@ -208,7 +208,7 @@ function create_odi_div(url)
|
|||
|
||||
var a = document.createElement("a");
|
||||
a.odi_div = div;
|
||||
a.innerHTML = get_basename(url);
|
||||
a.innerText = basename;
|
||||
a.target = "_blank";
|
||||
a.style.display = "block";
|
||||
a.href = url;
|
||||
|
@ -653,8 +653,8 @@ function lazy_load_all()
|
|||
return;
|
||||
}
|
||||
lazy_load_one(element, true);
|
||||
return
|
||||
;}
|
||||
return;
|
||||
}
|
||||
|
||||
function lazy_load_one(element, comeback)
|
||||
{
|
||||
|
@ -693,7 +693,7 @@ function normalize_url(url)
|
|||
}
|
||||
url = url.replace("http:", protocol);
|
||||
url = url.replace("https:", protocol);
|
||||
/*url = decodeURIComponent(unescape(url));*/
|
||||
|
||||
console.log(url);
|
||||
url = url.replace("imgur.com/gallery/", "imgur.com/a/");
|
||||
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
'''
|
||||
Search for a target string within the lines of files.
|
||||
|
||||
For example:
|
||||
fileswith.py *.py "import random"
|
||||
|
||||
Instead of a glob pattern, you can use a clipext !c or !i to take paths from your
|
||||
clipboard or stdin.
|
||||
|
||||
For example:
|
||||
dir /b | fileswith !i sampletext
|
||||
search .md | fileswith !i "^.{100}" --regex
|
||||
'''
|
||||
|
||||
import argparse
|
||||
import fnmatch
|
||||
import glob
|
||||
import re
|
||||
import sys
|
||||
|
||||
from voussoirkit import clipext
|
||||
from voussoirkit import pathclass
|
||||
from voussoirkit import safeprint
|
||||
from voussoirkit import spinal
|
||||
|
||||
|
||||
def get_filepaths(filepattern):
|
||||
original = filepattern
|
||||
filepattern = clipext.resolve(filepattern)
|
||||
if filepattern != original:
|
||||
lines = filepattern.splitlines()
|
||||
filepaths = [pathclass.Path(l) for l in lines]
|
||||
filepaths = [p for p in filepaths if p.is_file]
|
||||
else:
|
||||
filepaths = spinal.walk_generator(depth_first=False, yield_directories=True)
|
||||
for filepath in filepaths:
|
||||
if not fnmatch.fnmatch(filepath.basename, filepattern):
|
||||
continue
|
||||
if not filepath.is_file:
|
||||
continue
|
||||
return filepaths
|
||||
|
||||
def fileswith(
|
||||
filepattern,
|
||||
terms,
|
||||
case_sensitive=False,
|
||||
do_regex=False,
|
||||
do_glob=False,
|
||||
inverse=False,
|
||||
match_any=False,
|
||||
names_only=False,
|
||||
):
|
||||
|
||||
if not case_sensitive:
|
||||
terms = [term.lower() for term in terms]
|
||||
|
||||
def term_matches(text, term):
|
||||
return (
|
||||
(term in text) or
|
||||
(do_regex and re.search(term, text)) or
|
||||
(do_glob and fnmatch.fnmatch(text, term))
|
||||
)
|
||||
|
||||
anyall = any if match_any else all
|
||||
|
||||
|
||||
|
||||
filepaths = get_filepaths(filepattern)
|
||||
for filepath in filepaths:
|
||||
handle = open(filepath.absolute_path, 'r', encoding='utf-8')
|
||||
matches = []
|
||||
try:
|
||||
with handle:
|
||||
for (index, line) in enumerate(handle):
|
||||
if not case_sensitive:
|
||||
compare_line = line.lower()
|
||||
else:
|
||||
compare_line = line
|
||||
if inverse ^ anyall(term_matches(compare_line, term) for term in terms):
|
||||
line = '%d | %s' % (index+1, line.strip())
|
||||
if names_only:
|
||||
matches = True
|
||||
break
|
||||
matches.append(line)
|
||||
except:
|
||||
pass
|
||||
if matches:
|
||||
print(filepath.absolute_path)
|
||||
if names_only:
|
||||
continue
|
||||
safeprint.safeprint('\n'.join(matches))
|
||||
print()
|
||||
|
||||
|
||||
def fileswith_argparse(args):
|
||||
return fileswith(
|
||||
filepattern=args.filepattern,
|
||||
terms=args.search_terms,
|
||||
case_sensitive=args.case_sensitive,
|
||||
do_glob=args.do_glob,
|
||||
do_regex=args.do_regex,
|
||||
inverse=args.inverse,
|
||||
match_any=args.match_any,
|
||||
names_only=args.names_only,
|
||||
)
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('filepattern')
|
||||
parser.add_argument('search_terms', nargs='+', default=None)
|
||||
parser.add_argument('--any', dest='match_any', action='store_true')
|
||||
parser.add_argument('--case', dest='case_sensitive', action='store_true')
|
||||
parser.add_argument('--regex', dest='do_regex', action='store_true')
|
||||
parser.add_argument('--glob', dest='do_glob', action='store_true')
|
||||
parser.add_argument('--inverse', dest='inverse', action='store_true')
|
||||
parser.add_argument('--names_only', dest='names_only', action='store_true')
|
||||
parser.set_defaults(func=fileswith_argparse)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
args.func(args)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
|
@ -2,6 +2,8 @@ import sys
|
|||
|
||||
from voussoirkit import clipext
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
sys.argv.append('!i')
|
||||
text = clipext.resolve(sys.argv[1])
|
||||
lines = text.splitlines()
|
||||
digits = len(str(len(lines)))
|
||||
|
|
Loading…
Reference in a new issue