scripts

Utilitity scripts
git clone git://gtms.dev/scripts.git
Log | Files | Refs

commit f9ba87e90f93fab8249fac7c3c2b5d9d5465201d
parent 1cce3de3b2741adda40ddc8e8592b6ed7c9e53f2
Author: Tomas Nemec <nemi@skaut.cz>
Date:   Sat, 13 Nov 2021 12:27:36 +0100

update

Diffstat:
Abg_filter | 20++++++++++++++++++++
Abg_random | 29+++++++++++++++++++++++++++++
Mcht | 32+++++++++++++++-----------------
Mtmux-dev | 81+++++++++++++++++++++++++------------------------------------------------------
4 files changed, 89 insertions(+), 73 deletions(-)

diff --git a/bg_filter b/bg_filter @@ -0,0 +1,20 @@ +#!/usr/bin/env zsh + +filter="${1[1,1]}" +bg_dir="$HOME/bg" + +taller=0 +if [[ $filter == 't' ]]; then + taller=1 +fi + +IFS=$'\n' +for img in $(fd -t f . $bg_dir); do + IFS=' ' + identify -format '%w %h\n' "$img" | read w h + if [[ $w -gt $h ]]; then + [[ $taller -eq 0 ]] && echo $img + else + [[ $taller -eq 1 ]] && echo $img + fi +done diff --git a/bg_random b/bg_random @@ -0,0 +1,29 @@ +#!/usr/bin/env zsh +# Find for each monitor image relative to its resolutions. (wide/tall monitor) + +bg_dir="$HOME/bg" + +resolutions=($(\ + xrandr --listmonitors |\ + sed -n 's/.* \([[:digit:]]\+\)\/[[:digit:]]\+x\([[:digit:]]\+\)\/[[:digit:]]\+.*/\1x\2/p')) + +get_img(){ + if [[ ${1} == 'wide' ]]; then + echo "$(fd ^wide $bg_dir | shuf | head -1)" + else + echo "$(fd ^tall $bg_dir | shuf | head -1)" + fi +} + +typeset -a imgs +for res in "${resolutions[@]}"; do + echo $res | tr 'x' ' ' | read width height + if [[ (( $width > $height )) ]]; then + i=$(get_img 'wide') + else + i=$(get_img 'tall') + fi + imgs=($imgs $i) +done + +feh --bg-fill $imgs diff --git a/cht b/cht @@ -7,27 +7,25 @@ themes=(light dark) curr_theme=${THEME:-$CONFIG/theme} if [[ -z "$theme" ]]; then - echo "USAGE: cht <light|dark>" - exit 1 -fi - -if [[ ! -v SCHEME ]]; then - echo "SCHEME env is not set" >&2 - exit 1 + theme="$(cat $curr_theme)" fi if (($themes[(Ie)$theme])); then echo "$theme" > $curr_theme - # terminal - sed "s/^colors:.*/colors: *${SCHEME}_$theme/" -i $CONFIG/alacritty/alacritty.yml - # file manager - sed "s/^colorscheme .*/colorscheme: ${SCHEME}-$theme/" -i $CONFIG/vifm/vifmrc - # neovim - for sname in $(nvr --serverlist); do - nvr --servername "$sname" -cc "set background=${theme}" --nostart -s &; - done - # neomutt from $theme file (needs restart) - exit 0 + + img="$(cat $HOME/.fehbg | sed -n '2p' | cut -d ' ' -f 5)" + img="${img[2,-2]}" # remove quotes + if [[ ! -e "$img" ]]; then + echo "Image not found inside $HOME/.fehbg!" >&2 + exit 1 + fi + + # Generate colors from wallpaper + if [[ "$theme" == "dark" ]]; then + wal -n -i "$img" -o walset.zsh + else + wal -n -i "$img" -o walset.zsh -l + fi else echo "'$theme' is not a valid theme" echo "USAGE: cht <light|dark>" diff --git a/tmux-dev b/tmux-dev @@ -4,27 +4,26 @@ ------ CONFIGURATION ------- ----------------------------- local session = 'medoro' -- name for tmux session -local workdir = '~/dev/medoro/dpgw' -- your root dir for projects +local workdir = '~/dev/medoro' -- your root dir for projects +local pub = '~/.dswitch/channels/stable/versions/2.10.4/dart-sdk/bin/pub' local cmd = { - ui = 'pub get && pub run build_runner serve --delete-conflicting-outputs web:8081 >&1 > >(trun angulardart ui)', - dw = 'pub get && pub run build_runner serve --delete-conflicting-outputs web:8082 >&1 > >(trun angulardart dw)', - digi = 'pub get && pub run build_runner serve --delete-conflicting-outputs web:8083 >&1 > >(trun angulardart digi)', + ui = string.format( + '%s get && %s run build_runner serve --delete-conflicting-outputs web:8081 >&1 > >(trun angulardart ui)', pub, pub), + dw = string.format( + '%s get && %s run build_runner serve --delete-conflicting-outputs web:8082 >&1 > >(trun angulardart dw)', pub, pub), + digi = string.format( + '%s get && %s run build_runner serve --delete-conflicting-outputs web:8083 >&1 > >(trun angulardart digi)', pub, pub), dpgw = 'mvn compile && mvn exec:java -Dexec.mainClass=org.medoro.dpgw.DPGWMain', r_dpgw = 'mvn exec:java -Dexec.mainClass=org.medoro.dpgw.DPGWMain', } ------ APP DEFINITION ------- -- cwd: working directory -- cmd: command to start/restart -local dpgw = { - key = 'dpgw', - cwd = workdir .. '/dpgw', - cmd = cmd.dpgw, - r_cmd = cmd.r_dpgw, -} +local dpgw = {key = 'dpgw', cwd = workdir .. '/dpgw', cmd = cmd.dpgw, r_cmd = cmd.r_dpgw} local ui = {key = 'ui', cwd = workdir .. '/ui/branches/devel', cmd = cmd.ui} local dw = {key = 'dw', cwd = workdir .. '/dw/branches/devel', cmd = cmd.dw} -local digi = {key = 'digi', cwd = workdir .. '/digi', cmd = cmd.digi} +local digi = {key = 'digi', cwd = workdir .. '/digi/branches/devel', cmd = cmd.digi} -- COUPLES -- apps: list of app to make action on local stack = {key = 'stack', apps = {dpgw, ui, dw}} @@ -62,13 +61,7 @@ if #arg == 0 or arg[1] == '-h' or arg[1] == '--help' then end local actions = {start = 's', restart = 'r', stop = 't', open = 'o', join = 'j'} -- command mapping -local action_set = { - ['s'] = true, - ['r'] = true, - ['t'] = true, - ['o'] = true, - ['j'] = true, -} +local action_set = {['s'] = true, ['r'] = true, ['t'] = true, ['o'] = true, ['j'] = true} local action = string.sub(table.remove(arg, 1), 1, 1); -- get first char of command -- check for valid command if not action_set[action] then @@ -78,11 +71,8 @@ end -- make action if #arg == 0 and action == actions.stop then - local _, _, code = os.execute( - string.format('tmux kill-session -t %s', session)) - if code < 1 then - io.write('Stopped session', '\n') - end + local _, _, code = os.execute(string.format('tmux kill-session -t %s', session)) + if code < 1 then io.write('Stopped session', '\n') end os.exit(0) elseif #arg == 0 then os.exit(0) @@ -92,8 +82,7 @@ end ------ PROCESS UTILS ------- ----------------------------- local function started() - local _, _, code = os.execute(string.format('tmux has -t %s 2>> /dev/null', - session)) + local _, _, code = os.execute(string.format('tmux has -t %s 2>> /dev/null', session)) return code < 1 end local function run(cmd, ...) return os.execute(string.format(cmd, ...)) end @@ -103,28 +92,21 @@ local function run(cmd, ...) return os.execute(string.format(cmd, ...)) end -------------------------- local function tlocation(pane) local list = io.popen(string.format( - 'tmux lsp -s -t %s -F "#{pane_title} #{window_index} #{pane_index}" 2>> /dev/null', - session)) + 'tmux lsp -s -t %s -F "#{pane_title} #{window_index} #{pane_index}" 2>> /dev/null', session)) local location for line in list:lines() do local p, wi, pi = string.match(line, '^(%a+) (%d+) (%d+)$') - if p == pane then - location = string.format('%s:%s.%s', session, wi, pi) - end + if p == pane then location = string.format('%s:%s.%s', session, wi, pi) end end return location end local function tattach(pane) local location = tlocation(pane) - if location then - run('tmux a -t %s', location) - end + if location then run('tmux a -t %s', location) end end local function tkillp(pane) local location = tlocation(pane) - if location then - run('tmux killp -t %s', location) - end + if location then run('tmux killp -t %s', location) end end local function tnew(key, cwd) run('tmux neww -c %s -t %s -n %s', cwd, session, key) @@ -134,9 +116,7 @@ local function tsend(pane, cmds) local location = tlocation(pane) if location then if type(cmds) == 'table' then - for _, c in ipairs(cmds) do - run('tmux send -t %s "%s" enter', location, c) - end + for _, c in ipairs(cmds) do run('tmux send -t %s "%s" enter', location, c) end else run('tmux send -t %s "%s" enter', location, cmds) end @@ -182,9 +162,7 @@ end function App:open() local location = tlocation(self.key) - if location then - tattach(self.key) - end + if location then tattach(self.key) end end --- if pane exists @@ -195,9 +173,7 @@ end ------ CREATE APPS ------- local apps = {} -for _, app in ipairs(enabled_apps) do - apps[app.key] = App:new(app) -end +for _, app in ipairs(enabled_apps) do apps[app.key] = App:new(app) end -------------------------- ------ SESSION STARTED CHECK ------- @@ -228,9 +204,7 @@ for _, a in ipairs(arg) do -- COUPLES CHECK -- expand couples if app.apps then - for _, couple_apps in ipairs(app.apps) do - table.insert(curr_apps, couple_apps) - end + for _, couple_apps in ipairs(app.apps) do table.insert(curr_apps, couple_apps) end else table.insert(key_sequence, app) end @@ -245,9 +219,7 @@ end for _, capp in ipairs(curr_apps) do local slaves = {} -- apps to join if not capp.key then - for _, ca in ipairs(capp) do - table.insert(slaves, ca) - end + for _, ca in ipairs(capp) do table.insert(slaves, ca) end else table.insert(slaves, capp) end @@ -255,8 +227,7 @@ for _, capp in ipairs(curr_apps) do for _, app in ipairs(slaves) do if action == actions.start then if app:started() then - io.stderr:write(string.format('App \'%s\' is already running.\n', - app.key)) + io.stderr:write(string.format('App \'%s\' is already running.\n', app.key)) else app:start() end @@ -287,9 +258,7 @@ for _, capp in ipairs(curr_apps) do -- join slaves to master if action == actions.start or action == actions.join then local master = table.remove(slaves, 1) - for _, app in ipairs(slaves) do - tjoin(master.key, app.key) - end + for _, app in ipairs(slaves) do tjoin(master.key, app.key) end end end ------------------------