From 0f5bbd78ad97ae2b1e4ce698c5f62a59dcf06e12 Mon Sep 17 00:00:00 2001 From: Riley Housden Date: Sat, 25 Jun 2022 00:09:01 -0400 Subject: [PATCH] update --- .vimrc | 3 ++- .xonshrc | 5 +---- xontrib/jds.xsh | 41 +++++++++++++++++++++++++++++++++++++++++ xsh/aliases.xsh | 2 +- xsh/functions.xsh | 2 +- 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 xontrib/jds.xsh diff --git a/.vimrc b/.vimrc index e29dfdf..ae6c6f7 100644 --- a/.vimrc +++ b/.vimrc @@ -12,7 +12,6 @@ if $TERM == 'tmux-256color' let &t_8b = "\033[48;2;%lu;%lu;%lum" endif -set termguicolors set background=dark syntax enable @@ -66,5 +65,7 @@ Plug 'preservim/nerdtree' Plug 'chiel92/vim-autoformat' Plug 'natebosch/vim-lsc' Plug 'https://tildegit.org/sloum/gemini-vim-syntax' +Plug 'meatballs/vim-xonsh' +Plug 'davidhalter/jedi-vim' call plug#end() diff --git a/.xonshrc b/.xonshrc index fcbb16b..e7441ad 100644 --- a/.xonshrc +++ b/.xonshrc @@ -6,15 +6,12 @@ elif $HOSTNAME == "riley-server": elif $HOSTNAME == "riley-desktop": $PROMPT = '{RED} >< {RESET}| {BOLD_GREEN}{cwd_base}{RESET} ) ' $XONSH_COLOR_STYLE = 'default' -xontrib load argcomplete autovox jedi z bashisms +xontrib load argcomplete autovox jedi z bashisms jds source "~/xsh/functions.xsh" source "~/xsh/exceptions.xsh" source "~/xsh/aliases.xsh" -# TODO: Fix with Arch-based distros -# import addins # my extra stuffs :p - # Windows Subsystem for Linux stuff if in_wsl(): $GPG_TTY=$(tty) # allows gpg to work inside WSL diff --git a/xontrib/jds.xsh b/xontrib/jds.xsh new file mode 100644 index 0000000..eee1fb3 --- /dev/null +++ b/xontrib/jds.xsh @@ -0,0 +1,41 @@ +"""Integrates Johnny Decimal Notation into Xonsh""" + +from xonsh.built_ins import XSH + +HOME = p"/run/media/riley/drive" + +def find_category(number: int, path, regex: str): + """Find matching JDN folder when given notation""" + import re + folders = path.iterdir() + for folder in folders: + if not folder.is_dir(): + continue + folder_category = re.match(regex, folder.name) + if folder_category is None: + continue + if len(folder_category.groups()) == 2: + if number >= int(folder_category.group(1)) and number <= int(folder_category.group(2)): + return folder + elif len(folder_category.groups()) == 1: + if number == int(folder_category.group((1))): + return folder + return path + +@XSH.builtins.events.on_transform_command +def jds_preproc(cmd: str, **kw): + """processes command strings starting with "`" to cd to matching folder.""" + if cmd.startswith("`") and "." in cmd: + jdn = cmd.replace("`", "") + bucket = find_category(int(jdn.split(".")[0]), HOME, r"(^\d0)-(\d9)") + category = find_category(int(jdn.split(".")[0]), bucket, r"^(\d\d)") + folder = find_category(int(jdn.split(".")[1]), category, r"^(\d\d)") + cmd = f"cd '{folder.resolve()}'" + elif cmd.startswith("`"): + jdn = cmd.replace("`", "") + if jdn == "\n": + return f"cd '{HOME.resolve()}'" + bucket = find_category(int(jdn.split(".")[0]), HOME, r"(^\d0)-(\d9)") + category = find_category(int(jdn.split(".")[0]), bucket, r"^(\d\d)") + cmd = f"cd '{category.resolve()}'" + return cmd diff --git a/xsh/aliases.xsh b/xsh/aliases.xsh index 67710c6..743c585 100644 --- a/xsh/aliases.xsh +++ b/xsh/aliases.xsh @@ -1,4 +1,4 @@ -source xsh/functions.xsh +source ~/xsh/functions.xsh def _debug(): if $XONSH_SHOW_TRACEBACK: diff --git a/xsh/functions.xsh b/xsh/functions.xsh index 6439386..de77482 100644 --- a/xsh/functions.xsh +++ b/xsh/functions.xsh @@ -1,4 +1,4 @@ -source xsh/exceptions.xsh +source ~/xsh/exceptions.xsh def in_wsl() -> bool: """Determines if the system is running inside a WSL environment."""