Skip to content

Commit

Permalink
[shell] add .scripts folder
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofnds committed Aug 8, 2019
1 parent d2da78a commit 30f3d1c
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dot_aliases.tmpl
Expand Up @@ -58,6 +58,16 @@ update() {
asdf update
}

update!() {
update

syncgit

doom update
doom upgrade
doom autoremove
}

syncgit() {
pushd ~/org
git pull
Expand Down
79 changes: 79 additions & 0 deletions dot_scripts/executable_asdf-install-latest.rb
@@ -0,0 +1,79 @@
#!/usr/bin/env ruby

require 'scanf'

plugins = [
"clojure",
"crystal",
"dart",
"erlang",
"elixir",
"elm",
"golang",
"haskell",
# "java",
"kotlin",
"kubectl",
"minikube",
"nodejs",
"protoc",
"python",
"ruby",
"rust",
]

def fill(arr, len, fill_value)
len.times do |i|
if arr[i].nil?
arr[i] = fill_value
end
end
arr
end

def sem_ver(version_str)
major, minor, patch = version_str.scanf("%d.%d.%d")
fill([major, minor, patch], 3, 0)
end

def greater_version(a, b)
return -1 if a == 'stable'
return 1 if b == 'stable'

a_major, a_minor, a_patch = sem_ver(a)
b_major, b_minor, b_patch = sem_ver(b)

return -1 if a_major > b_major
return 1 if a_major < b_major

return -1 if a_minor > b_minor
return 1 if a_minor < b_minor

return -1 if a_patch > b_patch
return 1 if a_patch < b_patch

0
end

def install_plugin(plugin)
`asdf plugin-add #{plugin}`
sorted_versions =
`asdf list-all #{plugin}`
.split("\n")
.grep(/^(\d+(\.\d+){1,2}|stable)$/)
.sort { |a, b| greater_version(a, b) }

if sorted_versions.empty?
puts "could not find versions for #{plugin}"
else
latest_version = sorted_versions[0]
puts "installing #{plugin}: #{latest_version}"
`asdf install #{plugin} #{latest_version}`
puts "setting asdf global #{plugin} #{latest_version}"
`asdf global #{plugin} #{latest_version}`
end
end

plugins.each { |p| install_plugin(p) }

puts
13 changes: 13 additions & 0 deletions dot_scripts/executable_test-true-color.sh
@@ -0,0 +1,13 @@
awk 'BEGIN{
s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
for (colnum = 0; colnum<77; colnum++) {
r = 255-(colnum*255/76);
g = (colnum*510/76);
b = (colnum*255/76);
if (g>255) g = 510-g;
printf "\033[48;2;%d;%d;%dm", r,g,b;
printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
printf "%s\033[0m", substr(s,colnum+1,1);
}
printf "\n";
}'
26 changes: 26 additions & 0 deletions dot_scripts/power_menu.sh.tmpl
@@ -0,0 +1,26 @@
{{- if eq .chezmoi.os "linux" }}
#!/bin/bash

res=$(echo "lock|logout|reboot|shutdown|hibernate" | rofi -sep "|" -dmenu -i -p 'Power Menu: ' "" -width 9 -l 5 -hide-scrollbar -eh 4 -location 3 -yoffset 20 -padding 12 -opacity 100 -font "Misc Tamsyn 9" -auto-select -no-fullscreen)

if [ $res = "lock" ]; then
/usr/local/bin/lock.sh
fi

if [ $res = "logout" ]; then
i3-msg exit
fi

if [ $res = "reboot" ]; then
systemctl reboot
fi

if [ $res = "shutdown" ]; then
systemctl poweroff
fi

if [ $res = "hibernate" ]; then
systemctl hibernate
fi
exit 0
{{- end }}

0 comments on commit 30f3d1c

Please sign in to comment.