powershell support
This commit is contained in:
parent
58852ca83c
commit
997d1ee4de
8 changed files with 91 additions and 76 deletions
4
.config/micro/bindings.json
Normal file
4
.config/micro/bindings.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"Alt-/": "lua:comment.comment",
|
||||
"CtrlUnderscore": "lua:comment.comment"
|
||||
}
|
3
.config/micro/settings.json
Normal file
3
.config/micro/settings.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"colorscheme": "railscast"
|
||||
}
|
61
.config/micro/syntax/xonsh.yaml
Normal file
61
.config/micro/syntax/xonsh.yaml
Normal file
|
@ -0,0 +1,61 @@
|
|||
filetype: xonsh
|
||||
|
||||
detect:
|
||||
filename: "\\.xsh(3)?$|.xonshrc"
|
||||
|
||||
rules:
|
||||
# built-in objects
|
||||
- constant: "\\b(Ellipsis|None|self|cls|True|False)\\b"
|
||||
# built-in attributes
|
||||
- constant: "\\b(__bases__|__builtin__|__class__|__debug__|__dict__|__doc__|__file__|__members__|__methods__|__name__|__self__)\\b"
|
||||
# built-in functions
|
||||
- identifier: "\\b(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dir|divmod|eval|exec|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|max|min|next|nonlocal|oct|open|ord|pow|print|repr|round|setattr|sorted|sum|vars|__import__)\\b"
|
||||
# special method names
|
||||
- identifier: "\\b__(abs|add|and|call|cmp|coerce|complex|concat|contains|delattr|delitem|delslice|del|dict|divmod|div|float|getattr|getitem|getslice|hash|hex|iadd|iand|iconcat|ifloordiv|ilshift|imatmul|imod|imul|init|int|invert|inv|ior|ipow|irshift|isub|iter|itruediv|ixor|len|long|lshift|mod|mul|neg|next|nonzero|oct|or|pos|pow|radd|rand|rcmp|rdivmod|rdiv|repeat|repr|rlshift|rmod|rmul|ror|rpow|rrshift|rshift|rsub|rxor|setattr|setitem|setslice|str|sub|xor)__\\b"
|
||||
# types
|
||||
- type: "\\b(bool|bytearray|bytes|classmethod|complex|dict|enumerate|filter|float|frozenset|int|list|map|memoryview|object|property|range|reversed|set|slice|staticmethod|str|super|tuple|type|zip)\\b"
|
||||
# definitions
|
||||
- identifier: "def [a-zA-Z_0-9]+"
|
||||
# keywords
|
||||
- statement: "\\b(and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|raise|return|try|while|with|yield)\\b"
|
||||
# decorators
|
||||
- brightgreen: "@.*[(]"
|
||||
# operators
|
||||
- symbol.operator: "([~^.:;,+*|=!\\%@]|<|>|/|-|&)"
|
||||
# parentheses
|
||||
- symbol.brackets: "([(){}]|\\[|\\])"
|
||||
# numbers
|
||||
- constant.number: "\\b[0-9](_?[0-9])*(\\.([0-9](_?[0-9])*)?)?(e[0-9](_?[0-9])*)?\\b" # decimal
|
||||
- constant.number: "\\b0b(_?[01])+\\b" # bin
|
||||
- constant.number: "\\b0o(_?[0-7])+\\b" # oct
|
||||
- constant.number: "\\b0x(_?[0-9a-f])+\\b" # hex
|
||||
|
||||
- constant.string:
|
||||
start: "\"\"\""
|
||||
end: "\"\"\""
|
||||
rules: []
|
||||
|
||||
- constant.string:
|
||||
start: "'''"
|
||||
end: "'''"
|
||||
rules: []
|
||||
|
||||
- constant.string:
|
||||
start: "\""
|
||||
end: "(\"|$)"
|
||||
skip: "\\\\."
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
|
||||
- constant.string:
|
||||
start: "'"
|
||||
end: "('|$)"
|
||||
skip: "\\\\."
|
||||
rules:
|
||||
- constant.specialChar: "\\\\."
|
||||
|
||||
- comment:
|
||||
start: "#"
|
||||
end: "$"
|
||||
rules: # AKA Code tags (PEP 350)
|
||||
- todo: "(TODO|FIXME|HACK|BUG|NOTE|FAQ|MNEMONIC|REQ|RFE|IDEA|PORT|\\?\\?\\?|!!!|GLOSS|SEE|TODOC|STAT|RVD|CRED):?"
|
1
.xonshrc
1
.xonshrc
|
@ -27,6 +27,7 @@ append_path("~/go/bin")
|
|||
|
||||
if in_win():
|
||||
append_path("F:/programs/installed/micro")
|
||||
xontrib load ps1
|
||||
|
||||
# tmux
|
||||
try:
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
from .version import Version
|
||||
v = Version()
|
||||
|
||||
class Package:
|
||||
def __init__(self, name, source):
|
||||
self.name = name
|
||||
self.source = source
|
||||
self._installed = None
|
||||
|
||||
@property
|
||||
def installed(self):
|
||||
self._installed = self._get_installed()
|
||||
return self._installed
|
||||
|
||||
def _get_installed(self) -> bool:
|
||||
if self.source == 'apt':
|
||||
if !(dpkg -s @(self.name)).returncode == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
if self.source == 'npm':
|
||||
if !(npm list -g --parseable --silent @(self.name)).returncode == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return None
|
||||
|
||||
def install(self):
|
||||
if self.installed:
|
||||
print(f"package '{self.name}' already installed.")
|
||||
elif self.source == 'apt':
|
||||
$(sudo apt-get install -qq --yes @(self.name))
|
||||
elif self.source == 'npm':
|
||||
$(npm install -g --silent --yes @(self.name))
|
||||
elif self.source == 'pacman':
|
||||
$(pacman -Syu @(self.name))
|
||||
else:
|
||||
print(f"unsupported package manager '{source}'.")
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
__all__ = ['Version']
|
||||
|
||||
class Platform:
|
||||
def __init__(self):
|
||||
self.architecture = platform.architecture()
|
||||
self.machine = platform.machine()
|
||||
self.node = platform.node()
|
||||
self.platform = platform.platform()
|
||||
self.processor = platform.processor()
|
||||
self.release = platform.release()
|
||||
self.system = platform.system()
|
||||
self.version = platform.version()
|
||||
|
||||
class Version:
|
||||
def __init__(self):
|
||||
data = self._load_dict()
|
||||
for key, value in data.items():
|
||||
setattr(self, key.lower(), value)
|
||||
if hasattr(self, "id_like"): # special handling for ID_LIKE
|
||||
self.id_like = self.id_like.split()
|
||||
if not hasattr(self, "platform"):
|
||||
self.platform = Platform()
|
||||
|
||||
def _load_dict(self):
|
||||
data = {}
|
||||
os_files = Path('/etc').glob("*-release")
|
||||
for i in os_files:
|
||||
with i.open() as f:
|
||||
for line in f:
|
||||
line = line.split("=")
|
||||
data[line[0]] = line[1].strip().replace('"', '')
|
||||
return data
|
16
aliases.xsh
16
aliases.xsh
|
@ -77,6 +77,18 @@ def _colortest():
|
|||
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,
|
||||
|
@ -100,7 +112,9 @@ def load_aliases():
|
|||
if in_win():
|
||||
aliases.update({
|
||||
'config': 'git.exe --git-dir=$USERPROFILE/.cfg/ --work-tree=$USERPROFILE',
|
||||
'ls': $('dir') # get past namespace conflict with python's dir() function.
|
||||
'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():
|
||||
|
|
7
ps1.xsh
Normal file
7
ps1.xsh
Normal file
|
@ -0,0 +1,7 @@
|
|||
from xonsh.built_ins import XSH
|
||||
|
||||
@XSH.builtins.events.on_transform_command
|
||||
def ps1_preproc(cmd, **kw):
|
||||
if cmd.split(" ")[0].strip().endswith(".ps1"):
|
||||
cmd = f"powershell.exe {cmd}"
|
||||
return cmd
|
Loading…
Reference in a new issue