mirror of
https://github.com/Cian-H/dotfiles.git
synced 2026-03-13 16:42:49 +00:00
Changed . token to _dot
This change allows the dotfiles to work with chezmoi (e.g: on windows) and improves grepability with neovim/telescope
This commit is contained in:
36
dot_config/nushell/nu_scripts/sourced/fun/lisp_mode.nu
Normal file
36
dot_config/nushell/nu_scripts/sourced/fun/lisp_mode.nu
Normal file
@@ -0,0 +1,36 @@
|
||||
# Note: this requires the latest 0.32.1 or later
|
||||
#
|
||||
# usage:
|
||||
# > source lisp_mode.nu
|
||||
# > (echo (+ 1 (* 3 2)))
|
||||
|
||||
def "+" [x, y] { $x + $y }
|
||||
|
||||
def "-" [x, y] { $x - $y }
|
||||
|
||||
def "*" [x, y] { $x * $y }
|
||||
|
||||
def "/" [x, y] { $x / $y }
|
||||
|
||||
def in [x, y] { $x in $y }
|
||||
|
||||
def not-in [x, y] { $x not-in $y}
|
||||
|
||||
def "<" [x, y] { $x < $y }
|
||||
|
||||
def "<=" [x, y] { $x <= $y }
|
||||
|
||||
def ">" [x, y] { $x > $y }
|
||||
|
||||
def ">=" [x, y] { $x >= $y }
|
||||
|
||||
def "==" [x, y] { $x == $y }
|
||||
|
||||
def "!=" [x, y] { $x != $y }
|
||||
|
||||
def "=~" [x, y] { $x =~ $y }
|
||||
|
||||
def "!~" [x, y] { $x !~ $y }
|
||||
|
||||
def array [...rest] { echo $rest }
|
||||
|
||||
54
dot_config/nushell/nu_scripts/sourced/fun/spark.nu
Normal file
54
dot_config/nushell/nu_scripts/sourced/fun/spark.nu
Normal file
@@ -0,0 +1,54 @@
|
||||
let TICKS = [(char -u "2581")
|
||||
(char -u "2582")
|
||||
(char -u "2583")
|
||||
(char -u "2584")
|
||||
(char -u "2585")
|
||||
(char -u "2586")
|
||||
(char -u "2587")
|
||||
(char -u "2588")]
|
||||
|
||||
# send an array into spark and get a sparkline out
|
||||
# let v = [2, 250, 670, 890, 2, 430, 11, 908, 123, 57]
|
||||
# > spark $v
|
||||
# ▁▂▆▇▁▄▁█▁▁
|
||||
|
||||
# create a small sparkline graph
|
||||
def spark [v: list] {
|
||||
let min = ($v | math min)
|
||||
let max = ($v | math max)
|
||||
let ratio = (if $max == $min { 1.0 } else { 7.0 / ($max - $min)})
|
||||
$v | each { |e|
|
||||
let i = ((($e - $min) * $ratio) | math round)
|
||||
$"($TICKS | get $i)"
|
||||
} | str join
|
||||
}
|
||||
|
||||
def assert_eq [num: int, expected: string, input: list] {
|
||||
let actual = (spark2 $input)
|
||||
let span = (metadata $expected).span;
|
||||
if $actual != $expected {
|
||||
error make {
|
||||
msg: "Actual != Expected",
|
||||
label: {
|
||||
text: $"expected ($expected) but got ($actual)", start: $span.start, end: $span.end
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print $"Test ($num) (ansi green)passed(ansi reset) ✓"
|
||||
}
|
||||
}
|
||||
|
||||
def spark2_tests [] {
|
||||
assert_eq 1 "▁" [1.0]
|
||||
assert_eq 2 "▁▁" [1.0, 1.0]
|
||||
assert_eq 3 "▁▁▁▁" [1.0, 1.0, 1.0, 1.0]
|
||||
assert_eq 4 "▁▅▄▇▄█" [1.0, 1.3, 1.2, 1.4, 1.2, 1.5]
|
||||
assert_eq 5 "▁█▅" [-1.0, 1.0, 0.0]
|
||||
assert_eq 6 "▁▂█▅▂" [1.0, 5.0, 22.0, 13.0, 5.0]
|
||||
assert_eq 7 "▁▂▄▅▃█" [0.0, 30.0, 55.0, 80.0, 33.0, 150.0]
|
||||
assert_eq 8 "▁▁▁▁▃▁▁▁▂█" [1.0, 2.0, 3.0, 4.0, 100.0, 5.0, 10.0, 20.0, 50.0, 300.0]
|
||||
assert_eq 9 "▁▄█" [1.0, 50.0, 100.0]
|
||||
assert_eq 10 "▁▄█" [0.1, 5.0, 10.0]
|
||||
assert_eq 11 "▁▃█" [2.0, 4.0, 8.0]
|
||||
# assert_eq 12 "▁█" [2.0, 4.0, 8.0]
|
||||
}
|
||||
96
dot_config/nushell/nu_scripts/sourced/fun/website_builder.nu
Normal file
96
dot_config/nushell/nu_scripts/sourced/fun/website_builder.nu
Normal file
@@ -0,0 +1,96 @@
|
||||
# Converts markdown into their equivalent html pages
|
||||
let $markdown_files = (ls **/*.md)
|
||||
|
||||
for $markdown in $markdown_files {
|
||||
let $contents = (open --raw $markdown.name)
|
||||
|
||||
let $content_lines = ($contents | lines)
|
||||
|
||||
let $first_line = ($content_lines | first | str trim)
|
||||
|
||||
if $first_line == "---" {
|
||||
let $header = ($content_lines
|
||||
| skip 1
|
||||
| take while {|x| ($x | str trim) != "---"}
|
||||
| str join "\n"
|
||||
| from yaml)
|
||||
|
||||
let $post = ($content_lines
|
||||
| skip 1
|
||||
| skip while {|x| ($x | str trim) != "---"}
|
||||
| skip 1)
|
||||
|
||||
print $header
|
||||
|
||||
let $html_post = ($post
|
||||
| each {|line|
|
||||
if ($line | str starts-with "#") {
|
||||
let $line = ($line | str replace "^# (.*)$" "<h1>$1</h1>")
|
||||
let $line = ($line | str replace "^## (.*)$" "<h2>$1</h2>")
|
||||
let $line = ($line | str replace "^### (.*)$" "<h3>$1</h3>")
|
||||
|
||||
$line
|
||||
} else if $line != "" {
|
||||
# Otherwise, it's a paragraph
|
||||
# Convert images
|
||||
let $line = ($line | str replace --all '!\[(.+)\]\((.+)\)' '<img src="$2" alt="$1"/>')
|
||||
let $line = ($line | str replace --all 'src="../assets' 'src="assets')
|
||||
|
||||
# Convert links
|
||||
let $line = ($line | str replace --all '\[(.+?)\]\((.+?)\)' '<a href="$2">$1</a>')
|
||||
|
||||
# Convert code
|
||||
let $line = ($line | str replace --all '`(.+?)`' '<code>$1</code>')
|
||||
$"<p>($line)</p>"
|
||||
}
|
||||
})
|
||||
|
||||
let $html_post = ($html_post | str join "\n")
|
||||
let $html_post = $"<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>($header.title)</title>
|
||||
<style>
|
||||
img {
|
||||
max-width: 600px
|
||||
}
|
||||
p {
|
||||
display: block;
|
||||
margin-block-start: 1em;
|
||||
margin-block-end: 1em;
|
||||
margin-inline-start: 0px;
|
||||
margin-inline-end: 0px;
|
||||
}
|
||||
body {
|
||||
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
font-size: 16px;
|
||||
color: #2c3e50;
|
||||
line-height: 1.7;
|
||||
max-width: 740px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem 2.5rem;
|
||||
}
|
||||
code {
|
||||
color: #476582;
|
||||
padding: .25rem .5rem;
|
||||
margin: 0;
|
||||
font-size: .85em;
|
||||
background-color: #eeeeee;
|
||||
border-radius: 3px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
($html_post)
|
||||
</body>
|
||||
</html>"
|
||||
|
||||
# print $html_post
|
||||
|
||||
let $name = ($markdown.name | path parse | update extension "html" | path join)
|
||||
|
||||
$html_post | save --raw $name
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user