Skip to content

Commit

Permalink
Update jump_to_dir.py
Browse files Browse the repository at this point in the history
  • Loading branch information
anki-code authored Feb 22, 2024
1 parent 19b0800 commit 084991b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions xontrib/jump_to_dir.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Jump to used before directory by part of the path. Lightweight zero-dependency implementation of autojump or zoxide projects functionality. """

from xonsh.built_ins import XSH
import functools

_hist_backend = XSH.env.get('XONSH_HISTORY_BACKEND')

if _hist_backend == 'sqlite':
def _jump_to_dir(args):
def _jump_to_dir(args, search_column='cwd'):
import sqlite3 as _sqlite3
from pathlib import Path as _Path
con = _sqlite3.connect(XSH.env.get('XONSH_HISTORY_FILE'))
Expand All @@ -14,7 +15,11 @@ def _jump_to_dir(args):
cur = con.cursor()
sql = f"""
SELECT cwd FROM xonsh_history
WHERE cwd LIKE ? and cwd != ?
WHERE
{search_column} LIKE ?
AND cwd != ?
AND inp NOT LIKE 'j %'
AND inp NOT LIKE 'jc %'
GROUP BY cwd ORDER BY count(*) DESC
LIMIT 10"""
for row in cur.execute(sql, (f"%{'%'.join(args) if args else ''}%", XSH.env.get('PWD'))):
Expand All @@ -27,8 +32,9 @@ def _jump_to_dir(args):

return 0 if success else 1

aliases[__xonsh__.env.get('XONTRIB_JUMP_TO_DIR_SHORTCUT', 'j')] = _jump_to_dir
del _jump_to_dir
else:
aliases['j'] = functools.partial(_jump_to_dir, search_column='cwd')
aliases['jc'] = functools.partial(_jump_to_dir, search_column='inp')

elif __xonsh__.env.get('XONTRIB_JUMP_TO_DIR_WARNING', True):
print(f"xontrib-jump-to-dir: You're using {_hist_backend} for history backend. It's not supported for jump.")
print("xontrib-jump-to-dir: Feel free to contribute: https://github.com/anki-code/xontrib-jump-to-dir")

0 comments on commit 084991b

Please sign in to comment.