rearrange folder structure

This commit is contained in:
Riley Housden 2022-02-18 22:52:36 -05:00
parent 997d1ee4de
commit e0488cf830
Signed by: InValidFire
GPG key ID: 0D6208F6DF56B4D8
19 changed files with 5 additions and 9 deletions

123
xsh/aliases.xsh Normal file
View file

@ -0,0 +1,123 @@
source xsh/functions.xsh
def _debug():
if $XONSH_SHOW_TRACEBACK:
$XONSH_SHOW_TRACEBACK = False
print("Debug mode disabled.")
else:
$XONSH_SHOW_TRACEBACK = True
print("Debug mode enabled.")
def bw_get(object: str, bw_id: str, nulled: bool = False):
if nulled and in_win():
return !(bw get @(object) @(bw_id) a> nul)
elif nulled and not in_win():
return !(bw get @(object) @(bw_id) a> /dev/null)
return $(bw get @(object) @(bw_id))
def _bwc(args: list):
requires("bw")
if not p'~/.bw_session'.exists():
raise FileNotFoundError("~/.bw_session")
source ~/.bw_session
if args[0] == "full": # determine which keys to search for.
items = ["username", "password", "totp"]
elif args[0] == "password":
items = ["password", "totp"]
else:
items = [args[0]]
for i in items: # removes keys that don't exist for the object.
if not bw_get(i, args[1], True):
items.remove(i)
print(f"found: {', '.join(items)}")
for i in items: # actually copy the info to clipboard.
output = bw_get(i, args[1])
to_clipboard(output)
if items.index(i) < len(items) - 1:
input(f"copied {i}, press enter to continue")
else:
print(f"copied {i}")
def _mcrcon(args: list):
if p"~/.mcrcon".exists():
source "~/.mcrcon"
else:
raise FileNotFoundError("~/.mcrcon")
$(mcrcon @(" ".join(args)))
def _mcterm():
if p"~/.mcrcon".exists():
source "~/.mcrcon"
else:
raise FileNotFoundError("~/.mcrcon")
mcrcon -t
def _alias():
for alias in aliases:
if callable(aliases[alias]):
print(alias + " = ", aliases[alias].__name__)
else:
print(alias + " =", " ".join(aliases[alias]))
def _ensure_tmux(args: list):
if $XONSH_SHOW_TRACEBACK:
print(args)
if not $(tmux has-session -t @(args[0])):
tmux new-session -d -s @(args[0]) all> /dev/null
$(tmux send-keys -t @(args[0]) @(f"cd {args[1]}") C-m)
$(tmux send-keys -t @(args[0]) @(f"{args[2]}") C-m)
def _colortest():
import sys
for i in range(256):
sys.stdout.write(f"\033[48;5;{i}m ")
if (i+1) % 16 == 0:
sys.stdout.write("\033[0m\n")
def _ls():
from colorama import Fore, Back, Style
line_list = []
command = $(cmd /c dir)
for line in command.split("\n"):
line = [x for x in line.split(" ") if x]
if "<DIR>" in line:
line[-1] = f"{Fore.GREEN}{line[-1]}{Style.RESET_ALL}"
line = " ".join(line)
line_list.append(line)
[[print(x) for x in line_list]]
def load_aliases():
aliases.update({
'bwg': _bwc,
'colortest': _colortest,
'debug': _debug,
'ls': 'ls -alhs --color=auto',
'mc': _mcrcon,
'mct': _mcterm,
':q': 'exit',
'ensure-tmux': _ensure_tmux,
'aliases': _alias,
})
# WSL specific aliases
if in_wsl():
aliases.update({
'wh': "cd /mnt/c/Users/Riley",
})
# Windows specific aliases
if in_win():
aliases.update({
'config': 'git.exe --git-dir=$USERPROFILE/.cfg/ --work-tree=$USERPROFILE',
'ls': ['cmd', '/c', 'dir'], # get past namespace conflict with python's dir() function.
'lsn': _ls,
'lofi': ['powershell.exe', 'firefox.ps1', '-url', 'https://www.youtube.com/watch?v=5qap5aO4i9A/'],
})
if not in_win():
aliases.update({
'config': '/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME',
})

3
xsh/exceptions.xsh Normal file
View file

@ -0,0 +1,3 @@
class CommandNotFoundException(Exception):
def __init__(self, command):
super().__init__(f"Command '{command}' not found.")

41
xsh/functions.xsh Normal file
View file

@ -0,0 +1,41 @@
source xsh/exceptions.xsh
def in_wsl() -> bool:
"""Determines if the system is running inside a WSL environment."""
if in_win(): return False
version = p'/proc/version'.read_text()
if "microsoft" in version:
return True
return False
def in_win() -> bool:
"""Determines if the system is running inside a Windows environment."""
import os
if 'OS' in os.environ and os.environ['OS'] == "Windows_NT":
return True
return False
def to_clipboard(text: str):
"""Send text to the clipboard."""
if in_wsl() or in_win():
$(echo -n @(text) | clip.exe)
else:
requires("xclip")
$(echo -n @(text) | xclip -sel clipboard)
def requires(command: str):
"""Force exit the program if a required command is not found."""
if not !(which @(command)):
raise CommandNotFoundException(command)
return True
def append_path(path: str):
"""Append a path to the end of the system's PATH variable."""
import sys
$PATH.extend([path])
# enables us to import and use modules in the current working directory
if sys.path[0] != '':
sys.path.insert(0, '')