Skip to content

Instantly share code, notes, and snippets.

@lmorg
Last active November 11, 2020 09:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmorg/95622fd57f2091cdfe632c47d004cb23 to your computer and use it in GitHub Desktop.
Save lmorg/95622fd57f2091cdfe632c47d004cb23 to your computer and use it in GitHub Desktop.
My murex profile
#export PATH=$PATH:$GOPATH/bin:~/bin:~/.cargo/bin
export EDITOR=vi
# Improve readability of `ls`
export TIME_STYLE=long-iso
export BLOCK_SIZE="'1"
alias grep=grep --color=auto
if { os linux } then { alias ls=ls --color=auto }
config: set shell spellcheck-enabled true
if { which vim } then { alias vi=vim }
# https://github.com/sharkdp/bat
if { which bat } then {
alias cat=bat
summary cat ${man-summary cat}
}
# https://github.com/sharkdp/lsd
# https://github.com/ryanoasis/nerd-fonts/
#if { which lsd } then {
# alias ls=lsd
# summary ls ${man-summary ls}
#}
config set shell max-suggestions 12
function pless {
# less for JSON
-> trypipe { -> pretty -> less }
}
function chdir {
# make a directory then change to that new dir (assumes `-p` flag where supported)
try {
switch ${os} {
case windows { tout json {} }
case linux { tout json {[ "-p", "--" ]} }
catch { tout json {[ "-p" ]} }
} -> set flags
mkdir @flags $ARGS[1]
cd $ARGS[1]
}
}
function pwd_short {
# Normalise path to it's short form
pwd -> regexp "s#^$HOME#\~#"
}
config: set shell prompt {
exitnum -> !if {
out "{RESET}{YELLOW}${pwd_short} {GREEN}»{RESET} "
} else {
out "{RESET}{YELLOW}${pwd_short} {RED}»{RESET} "
}
}
config: set shell prompt-multiline {
let len = ${pwd_short -> wc -c} - 1
printf "%${$len}s » " $linenum
}
#config: set shell hint-text-formatting "{ALT-FONT-1}{BLUE}"
#function funcs {
# # Returns a human readable list of murex functions
# runtime: --funcs -> formap k v { printf "%20s => %s\n" $k $v[Summary] } -> sort
#}
# So I can use the same murex profile on FreeBSD without creating unsupported
# functions nor aliases
if { os linux } then {
# ip -brief -color address
alias ipip=ip -br -c a
# ip -brief -color link
alias ipmac=ip -br -c l
function fix_mac_keyboard {
# Corrects the function keys on some MacBooks running Linux
#echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode
echo 2 | sudo tee /sys/module/applespi/parameters/fnmode
}
}
function qrmfa {
# Generates a QR code for Google Authenticator based on the gopass output
-> set gopass
set creds
try {
$gopass -> set yaml creds
}; catch {
$gopass -> sed 1d -> set yaml creds
}
config set index silent true
$creds[Account\sNumber] -> set str account
$creds[Email] -> set str email
$creds[MFA\sSecret] -> set str secret
!if { $secret } then { $creds[TOTP] -> set str secret }
!if { $account } then { read account "Account name: " }
!if { $email } then { read email "Email: " }
(otpauth://totp/$email:$account?secret=$secret) -> qr -> open
}
#########
## IDE ##
#########
function github_token {
# Sets my Github token (eg for Terraform)
set token=hQEMAzU2n9AgSSJCAQf/cDoPCNcuMj4b5KL6yec0fKivMi0o9i6oJcHVwxDUVNnuriBk03at54Da06VgaYq6w/o9NnxUSIaL7v7PHoafP34dzoi0fGdldcjJ5R2t3AfVYy6wf8mSNwqbGozTa9Fbqq1JEJ/9D0bx7dKs0PsiRQMyApW58GdHMmZnY874v4qo6s9S9UF0CDtbZbEPdyVNGEaFhQ9z8tlOBddPZEtDitgGsdyCbYo83hB+i5okuIbhujdKqhx5izCOypq6bxmQVvUs1sU7fDKRI+H/WnTwRGK7oDcMvPIW5zv1kVW9QsoK3DJ5f4hKbaSiktA/yHttrCAGGX3/ScXjU6NPiGxSRNJjARzQgT1USad2n58mY7YJlrEhoh3MpDojNvoV+lWEYggrjgiAl13Y0cmjPmFIGwJxj2z3cwUMc0zQT3fNZYFJJIznE29tOydHOYHltXerbbBWhk1betMDvs1gMQXT4wkwsEuY
($token) -> !base64 -> gpg --decrypt -> export GITHUB_TOKEN
source {
config set http default-https true
config alter http headers /api.github.com ({
"Authorization": "token $GITHUB_TOKEN"
})
}
}
alias todo=todo --database ~/.todo
summary todo "todo - a reminder/task program aimed at developers"
private todo.map.tasks {
todo -> set todo
map { $todo -> regexp 'f/^\s+([0-9]+)\..*$' } { $todo -> regexp 'f/^\s+[0-9]+\.(.*)$' }
}
autocomplete set todo {
[
{
"Dynamic": ({
todo --help -> regexp 'f/(--[-a-zA-Z0-9]+)/' -> sort -> uniq
}),
"FlagValues": {
"--remove": [{
"DynamicDesc": ({ todo.map.tasks }),
"ListView": true,
"AllowMultiple": true
}],
"--edit": [{
"DynamicDesc": ({ todo.map.tasks }),
"ListView": true
}],
"-e": [{
"DynamicDesc": ({ todo.map.tasks }),
"ListView": true
}],
"--done": [{
"DynamicDesc": ({ todo.map.tasks }),
"ListView": true,
"AllowMultiple": true
}],
"-d": [{
"DynamicDesc": ({ todo.map.tasks }),
"ListView": true,
"AllowMultiple": true
}]
}
}
]
}
config set shell hint-text-func {
trypipe <!null> {
git status --porcelain -b -> set gitstatus
#$gitstatus -> head -n1 -> sed -r 's/^## //;s/\.\.\./ => /' -> set gitbranch
$gitstatus -> head -n1 -> regexp 's/^## //' -> regexp 's/\.\.\./ => /' -> set gitbranch
let gitchanges=${ out $gitstatus -> sed 1d -> wc -l }
!if { $gitchanges } then { ({GREEN}) } else { ({RED}) }
(Git{BLUE}: $gitbranch ($gitchanges pending). )
}
catch {
({YELLOW}Git{BLUE}: Not a git repository. )
}
if { $SSH_AGENT_PID } then {
({GREEN}ssh-agent{BLUE}: $SSH_AGENT_PID. )
} else {
({RED}ssh-agent{BLUE}: No env set. )
}
if { pgrep: vpnc } then {
({YELLOW}VPN{BLUE}: vpnc is active. )
}
if { ps aux -> regexp m/openvpn --errors-to-stderr --log/ } then {
({YELLOW}VPN{BLUE}: openvpn is active. )
}
trypipe <!null> {
open: main.tf -> format json -> [ terraform ] -> [ 0 ] -> [ required_version ] -> sed -r 's/\s0\./ /' -> set tfmod
terraform: version -> head -n1 -> regexp (f/Terraform v0\.([0-9.]+)$) -> set tfver
if { = tfmod >= tfver } then { ({GREEN}) } else { ({RED}) }
(Terraform{BLUE}: $tfver; required $tfmod. )
}
if { $AWS_SESSION_TOKEN } then {
set aws_expiration
set int date=${ date +%s }
if { os linux } then {
set int aws_expiration=${ date -d $AWS_SESSION_EXPIRATION +%s }
} else {
set int aws_expiration=${ date -j -f "%FT%R:%SZ" $AWS_SESSION_EXPIRATION +%s }
}
= (($aws_expiration-$date)/60) -> format int -> set aws_session_time
if { = aws_session_time < 1 } then { ({RED}) } else { ({GREEN}) }
(awscon{BLUE}: $AWS_SESSION_NAME => $aws_session_time mins. )
}
}
############
## AWSCON ##
############
if { g: ~/dev/python/infra-aws-assume-role/aws_assume_role.py } then {
function awscon {
# Authenticates with AWS using multi-factor authentication
$ARGS -> [ <!null> 2 ] -> set mfatoken
try {
if { $mfatoken } else {
read mfatoken "Please enter the 6 digit AWS identities MFA: "
}
python ~/dev/python/infra-aws-assume-role/aws_assume_role.py --profile $ARGS[1] --MFAtoken $mfatoken -> source
}
}
autocomplete set awscon { [{
"Dynamic": ({
trypipe {
open terraform.tfvars -> [ aws_account_id ] -> set accid
grep $accid ~/.aws/config -n -> regexp 'f/(^[0-9]+)' -> set int line
let line=line-3
cat ~/.aws/config -> @[$line..$line]n -> regexp 'f/^\[profile (.*?)\]/'
}; catch {
cat ~/.aws/config -> regexp 'f/^\[profile (.*?)\]/' -> sort
}
})
}] }
}
###########
## VAULT ##
###########
autocomplete set vault { [{
"Flags": ["audit-disable","audit-enable","audit-list","auth","auth-disable","auth-enable","capabilities","delete","generate-root","init","key-status","list","mount","mounts","mount-tune","path-help","policies","policy-delete","policy-write","read","rekey","remount","renew","revoke","rotate","seal","server","ssh","status","step-down","token-create","token-lookup","token-renew","token-revoke","unmount","unseal","unwrap","version","write"]
}] }
#############
## KEYBASE ##
#############
autocomplete set keybase { [{
"DynamicDesc": ({
#keybase: -> @[ ^COMMANDS:\$..^\$ ]re -> sort -> set keybase
#map { $keybase[ :0 ] -> regexp s/,// } { $keybase -> regexp 'f/\t+(.*?)$' }
keybase -> @[^COMMANDS..^ADDITIONAL]re -> tabulate: --split-comma --map
}),
"ListView": true,
"FlagValues": {
"pgp": [{
"DynamicDesc": ({
keybase help pgp -> @[^COMMANDS..^ADDITIONAL]re -> tabulate: --split-comma --map
}),
"ListView": true
}]
}
}] }
###############
## CONCOURSE ##
###############
summary fly "Concourse - The `fly` CLI"
autocomplete set fly {
[
{
"DynamicDesc": ({
fly -> match: -- -> set fly
map {
$fly: -> regexp: (f/(--.*?)[\s\t])
} {
$fly: -> regexp: (m/--/) -> regexp: (f/--.*? +(.*))
}
}),
"Optional": true,
"AllowMultiple": true
},
{
"DynamicDesc": ({
fly -> @[Available commands:..]se -> set fly
map { $fly[:0] } { $fly -> regexp 'f/^ +.*? +(.*?)$/' -> regexp 's/\(.*?\)//'}
}),
"AllowMultiple": true,
"AllowOther": true
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment