-
Notifications
You must be signed in to change notification settings - Fork 1
/
xonsh_aliases.xsh
79 lines (64 loc) · 2.9 KB
/
xonsh_aliases.xsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def _it(args, stdin=None):
"Easily pipe to and from $it"
if stdin is None: # No input, output $it
return "{}".format(${...}.get("it", ""))
else: # Stash input into $it
$it = stdin.read()
return $it if "-q" not in args else ""
aliases["it"] = _it
# alias pbq='pbpaste | sed -e "s/^/> /" | pbcopy'
def _pbq(args, stdin=None):
"Adds '> ' to the lines in the pasteboard so they can be pasted as a Markdown block quote"
lines = [ f"> {s}" for s in !(pbpaste) ]
echo -n @("".join(lines)) | pbcopy
return None
aliases["pbq"] = _pbq
# Rewraps lines in the pasteboard so they are at most 72 characters long
# alias pbw='pbpaste | fmt -72 | pbcopy'
aliases["pbw"] = lambda: $[pbpaste | fmt | pbcopy] # pipelines in aliases are tricky
# Sorts lines in the pasteboard
# alias pbs='pbpaste | sort | pbcopy'
aliases["pbs"] = lambda: $[pbpaste | sort | pbcopy]
# Format json with jq - brew install jq
# alias pbw='pbpaste | jq "." | pbcopy'
aliases["pbjq"] = lambda: $[pbpaste | jq '.' | pbcopy]
# alias pbdotpath='pbpaste | sed -e "s/\\.[^.]*$//" | tr "/" "." | pbcopy'
aliases["pbdotpath"] = lambda: $[pbpaste | sed -e 's/\\.[^.]*$//' | tr "/" "." | pbcopy]
# alias pbc='pbpaste | sed -e "s/ # .*//" -e "s/^#.*//" -e "/^ *$/d" | pbcopy'
# aliases["pbc"] = lambda: $[pbpaste | sed -e "s/ # .*//" -e "s/^#.*//" -e "/^ *$/d" | pbcopy]
def _pbc(args, stdin=None):
"Strips #-style comments from the lines in the pasteboard so they can be pasted"
lines = !(pbpaste)
lines = ( re.sub(r"(^#.*$)|(\s+#\s.*$)", "", l) for l in lines )
lines = ( l for l in lines if re.search(r"\S", l))
echo -n @("".join(lines)) | pbcopy
return None
aliases["pbc"] = _pbc
# alias pbl='pbpaste | tr 'A-Z' 'a-z' | pbcopy'
def _pbl(args, stdin=None):
"Lowercase text on the pasteboard"
lines = [ s.lower() for s in !(pbpaste) ]
echo -n @("".join(lines)) | pbcopy
return None
aliases["pbl"] = _pbl
# alias pbu='pbpaste | tr 'a-z' 'A-Z' | pbcopy'
def _pbu(args, stdin=None):
"Uppercase text on the pasteboard"
lines = [ s.upper() for s in !(pbpaste) ]
echo -n @("".join(lines)) | pbcopy
return None
aliases["pbu"] = _pbu
# alias pbsqlfix='pbpaste | sqlfluff fix --dialect postgres - | pbcopy' # FIXME: translate fix-or-lint/format into standard alias
aliases["pbsqlfix"] = lambda: $[pbpaste | sqlfluff fix --dialect postgres - | pbcopy] or $[pbpaste | sqlfluff lint --dialect postgres -]
aliases["adb"] = "~/Library/Android/sdk/platform-tools/adb"
aliases["ag"] = "allgit"
if !(which allgit_dev): # Special symlink to keep uing the dev version
aliases["ag"] = "allgit_dev"
aliases["dkr"] = "docker"
aliases["dkc"] = "docker-compose"
aliases["tf"] = "terraform"
aliases["per"] = "pipenv run"
# Snippets:
aliases["snip-clog"] = lambda: $[echo 'console.log({ "": {}, }) // BJH: NOCOMMIT ' | pbcopy]
aliases["snip-eslint"] = lambda: $[echo '// eslint-disable-next-line ' | pbcopy]
###