using hlwm attrs instead of universal flags. files can have custom colors set per-filename. general unfuckyness

This commit is contained in:
emilis 2023-01-05 16:33:27 +00:00
parent fa1d9d0944
commit 8c396b7101
18 changed files with 290 additions and 190 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
helix/runtime
fish/fish_variables
# openbsd crash core dumps
*.core
*.log

View File

@ -12,7 +12,7 @@
# - /path/to/alacritty.yml
import:
- ~/.alacritty-colorscheme/themes/xterm.yaml
- ~/.alacrittyrc.yaml
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty itself.
@ -22,7 +22,7 @@ env:
# This value is used to set the `$TERM` environment variable for
# each instance of Alacritty. If it is not present, alacritty will
# check the local terminfo database and use `alacritty` if it is
# available, otherwise `xterm-256color` is used.
# available, otherwise `xterm-256color` i_configs used.
TERM: alacritty
#window:
@ -175,7 +175,7 @@ env:
#use_thin_strokes: true
# If `true`, bold text is drawn using the bright color variants.
#draw_bold_text_with_bright_colors: false
draw_bold_text_with_bright_colors: false
# Colors (Tomorrow Night)
#colors:
@ -409,7 +409,7 @@ env:
#thickness: 0.15
# Live config reload (changes require restart)
#live_config_reload: true
live_config_reload: true
# Shell
#

View File

@ -3,5 +3,9 @@ set -x TERM "xterm-256color"
alias hc=herbstclient
set fish_greeting ""
# Add local bin paths
fish_add_path $HOME/.cargo/bin
fish_add_path $HOME/.bin
# Local per-machine changes
source $HOME/.fishrc

View File

@ -1,34 +1,18 @@
#!/usr/bin/env
function parent_dir
set -f trace (status stack-trace)
# By index:
# 1: in command substitution
# 2: parent.fish line
# 3: in function 'parent'
# 4: caller import line
# 5: in command substitution
# 6: caller "parent" invokation line
# 7: in function calling parent
# 8: jackpot! here's the parent of the caller
set -f parent_line $trace[8]
set -f parent_split (string split 'of file' $parent_line)
set -f parent (string trim $parent_split[2])
# qualify ~
set -f parent (string replace '~' "$HOME" $parent)
# Qualify the path to absolute and remove the filename
set -f parent_dir (realpath $parent)
set -f parent (string join '/' (string split '/' $parent_dir)[1..-2])
echo $parent
end
source (status dirname)/../include/parent.fish
function import
set -f self_directory (parent_dir)
set -f self_directory (parent_script_dir)
if set -q debug;
echo "importing $argv.fish from [$self_directory]"
end
if starts_with '@' "$argv"
set -f include_dir "$(status dirname)/../include/"
set -f import_path \
(string replace '@' "$include_dir" "$argv")
source "$import_path.fish"
return 0
end
if starts_with '/' "$argv"
source "$argv.fish"
return 0

27
fish/functions/log.fish Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env fish
import @parent
# calls logger with a specific color
#
# examples:
#
# log "hello there"
# log -c magenta "im berry"
# log --color cc00cc "just like the blueberries"
function log
set -f log_name (parent_script)
# hlwm config particular
set -f cfg_color \
(hc attr settings.my_Color_$log_name 2> /dev/null)
argparse 'c/color=' -- $argv
if not set -q _flag_color; or test -n "$_flag_color"
if test -n "$cfg_color"
set -g _flag_color $cfg_color
else
set -g _flag_color green
end
end
echo -s "[ " (set_color $_flag_color) $log_name (set_color normal) " ]: $argv" 1>&2
end

51
fish/include/parent.fish Executable file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env fish
# parent_script prints the parent script's filename
function parent_script
set -f trace (status stack-trace)
# By index:
# 1: in command substitution
# 2: parent.fish line
# 3: in function 'parent'
# 4: caller import line
# 5: in command substitution
# 6: caller "parent" invokation line
# 7: in function calling parent
# 8: jackpot! here's the parent of the caller
set -f parent_line $trace[8]
set -f parent_split (string split 'of file' $parent_line)
set -f parent (string trim $parent_split[2])
# Clean up the parent a lil bit
set -f parent (realpath (string replace '~' "$HOME" $parent))
set -f parent_parts (string split '/' $parent)
set -f parent (string join '/' $parent_parts[-1])
# remove .fish suffix
set -f parent (string replace '.fish' '' $parent)
echo $parent
end
function parent_script_dir
set -f trace (status stack-trace)
# By index:
# 1: in command substitution
# 2: parent.fish line
# 3: in function 'parent'
# 4: caller import line
# 5: in command substitution
# 6: caller "parent" invokation line
# 7: in function calling parent
# 8: jackpot! here's the parent of the caller
set -f parent_line $trace[8]
set -f parent_split (string split 'of file' $parent_line)
set -f parent (string trim $parent_split[2])
# qualify ~
set -f parent (string replace '~' "$HOME" $parent)
# Qualify the path to absolute and remove the filename
set -f parent_dir (realpath $parent)
set -f parent (string join '/' (string split '/' $parent_dir)[1..-2])
echo $parent
end

View File

@ -6,4 +6,4 @@ auto-completion = true
#left = ["mode", "spinner"]
[editor.lsp]
display-messages = true
# display-messages = true

View File

@ -1,9 +0,0 @@
#!/usr/bin/env fish
set -g FISH_CMDS_PATH $HOME/.config/herbstluftwm/fish_cmds
# cmd_string returns the shell command to invoke
# the fish_cmds file title given to it as an argument
function cmd_string
set -f FISH_PATH (status fish-path)
printf "$FISH_PATH\n$FISH_CMDS_PATH/$argv.fish"
end

View File

@ -1,13 +0,0 @@
#!/usr/bin/env fish
function hlwm_active
echo (herbstclient attr theme.active.color)
end
function hlwm_normal
echo (herbstclient attr theme.normal.color)
end
function hlwm_text
echo (herbstclient attr theme.normal.title_color)
end

View File

@ -0,0 +1,48 @@
#!/usr/bin/env fish
import @parent
alias hc=herbstclient
function new_config
argparse -i 'n/name=' 'v/value=' 't/type=' -- $argv
set_default _flag_type 'string'
if test -z "$_flag_name"; or test -z "$_flag_value"
log -c 'red' "name and value must be set"
return 1
end
set -f cfg_name (printf 'settings.my_%s' $_flag_name)
hc get_attr settings.my_$_flag_name &> /dev/null
if test $status -eq 0
hc set_attr "settings.my_$_flag_name" \
$_flag_value #&> /dev/null
else
hc new_attr "$_flag_type" \
"$cfg_name" \
"$_flag_value" #&> /dev/null
end
end
function set_config
argparse -i 'n/name=' 'v/value=' -- $argv
if test -z "$_flag_name"; or test -z "$_flag_value";
log -c 'red' "name and value must be set"
return 1
end
set -f cfg_name (printf 'settings.my_%s' $_flag_name)
hc set_attr $cfg_name $_flag_value
end
function get_config
set -f cfg_name (printf 'settings.my_%s' "$argv")
hc get_attr $cfg_name
end
function set_log_color
set -f parent (parent_script)
new_config \
-t string \
-n "$(printf 'Color_%s' "$parent")" \
-v "$argv"
end

View File

@ -1,18 +1,21 @@
#!/usr/bin/env
import notify
import log
import config
alias hc=herbstclient
set -g tag_color "ff99cc"
set_log_color "ff99cc"
# group_active_reset resets the active group (unset)
# group_active_reset resets the active group to 1
function group_active_reset
set -q hlwm_group_active
new_config \
-t uint \
-n ActiveGroup \
-v 1
end
function group_switch
set -f current $hlwm_group_active
set -f current (get_config ActiveGroup)
set -f arg $argv[1]
if not set -q arg
@ -26,33 +29,36 @@ function group_switch
# is a number
group_index $arg
else
log -c $tag_color "invalid group index [$arg], use '+', '-', or a real integer"
log "invalid group index [$arg], use '+', '-', or a real integer"
return 1
end
# update the tag it should now be on, if it switched
if test $hlwm_group_active -ne $current
if test (get_config ActiveGroup) -ne $current
update_tag $current
end
group_set_keybinds
notify "Group $hlwm_group_active"
log -c $tag_color "group $current -> $hlwm_group_active"
set -f active (get_config ActiveGroup)
notify "Group $active"
log "group $current -> $active"
end
# move_to_group moves the focused window to the relative tag on
# a given group
# move_to_group moves the focused window to the
# relative tag on a given group
function move_to_group
set -f move_to "$argv"
if test "$move_to" = "$hlwm_group_active"
log -c $tag_color "ignoring move as it's already in the active group"
set -f active (get_config ActiveGroup)
if test "$move_to" = "$active"
log "ignoring move as it's already in the active group"
return 0
else if test $move_to -lt 1 -o $move_to -gt $hlwm_group_count
log -c $tag_color "invalid group index [$move_to]:" \
"out of range [1:$hlwm_group_count]"
else if test $move_to -lt 1; or \
$move_to -gt (get_config GroupCount)
log "invalid group index [$move_to]:" \
"out of range [1:$(get_config GroupCount)]"
return 1
end
set -f new_tag (translate_tag $hlwm_group_active $move_to)
log -c $tag_color "moving window to group [$move_to]" \
set -f new_tag (translate_tag $active $move_to)
log "moving window to group [$move_to]" \
"tag -> $new_tag"
end
@ -64,66 +70,83 @@ function translate_tag
set -f current_actual (hc attr tags.focus.index)
set -f tl_from $argv[1]
set -f tl_to $argv[2]
set -f offset_from (math (math $tl_from - 1) x $hlwm_tags_per_group)
set -f offset_to (math (math $tl_to - 1) x $hlwm_tags_per_group)
set -f relative_tag_from (math $current_actual - $offset_from)
log -c $tag_color \
"calculated relative tag to group [$tl_from] to be [$relative_tag_from]"
set -f actual_tag_to (math $relative_tag_from + $offset_to)
log -c $tag_color \
"relative tag [$relative_tag_from] translated to group [$tl_to]" \
set -f offset_from \
(math \
(math $tl_from - 1) x \
(get_config TagsPerGroup))
set -f offset_to \
(math \
(math $tl_to - 1) x \
(get_config TagsPerGroup))
set -f relative_tag_from \
(math $current_actual - $offset_from)
log \
"calculated relative tag to" \
"group [$tl_from] to be" \
"[$relative_tag_from]"
set -f actual_tag_to \
(math $relative_tag_from + $offset_to)
log \
"relative tag" \
"[$relative_tag_from]" \
"translated to group [$tl_to]"\
"becomes actual tag [$actual_tag_to]"
echo $actual_tag_to
end
function update_tag
set -f new_tag (translate_tag $argv $hlwm_group_active)
log -c $tag_color "moving frame focus to tag: [$new_tag]"
set -f new_tag (translate_tag $argv \
$(get_config ActiveGroup))
log "moving frame focus to tag: [$new_tag]"
hc use_index $new_tag
end
function group_down
if not set -q hlwm_group_active
set -f active_grp (get_config ActiveGroup)
if not set -q active_grp; or \
test $active_grp -eq 1
# Treat unset == 1, so move back to the last one
set -U hlwm_group_active $hlwm_group_count
else if test $hlwm_group_active -eq 1
set -U hlwm_group_active $hlwm_group_count
set_config -n ActiveGroup -v (get_config GroupCount)
else
set -U hlwm_group_active (math $hlwm_group_active - 1)
set_config -n ActiveGroup -v (math $active_grp - 1)
end
end
function group_up
set -f active_grp (get_config ActiveGroup)
if test $active_grp -le 1
set_config -n ActiveGroup -v 2
else if test $active_grp -eq (get_config GroupCount)
set_config -n ActiveGroup -v 1
else
set_config -n ActiveGroup \
-v (math $active_grp + 1)
end
end
function group_index
if test $argv -gt $hlwm_group_count
set -f $argv $hlwm_group_count
if test $argv -gt (get_config GroupCount)
set -f $argv (get_config GroupCount)
else if test $argv -lt 1
set -f $argv 1
end
set -U hlwm_group_active $argv
end
function group_up
if not set -q hlwm_group_active
set -U hlwm_group_active 2
else if test $hlwm_group_active -eq $hlwm_group_count
set -U hlwm_group_active 1
else
set -U hlwm_group_active (math $hlwm_group_active + 1)
end
set_config -n ActiveGroup -v $argv
end
# group_set_keybinds sets the keybinds to the given tab group
function group_set_keybinds
set_default hlwm_mod Mod4
log -c $tag_color "setting keybinds for group: $hlwm_group_active"
if not set -q hlwm_group_active;
set -U hlwm_group_active 1
end
set -l offset (math (math $hlwm_group_active-1) x $hlwm_tags_per_group)
for tag in (seq $hlwm_tags_per_group)
set_default hlwm_mod (get_config ModKey)
set -f grp (get_config ActiveGroup)
set -f tags_per (get_config TagsPerGroup)
log "setting keybinds for group: $grp"
set -l offset (math \
(math $grp-1) x $tags_per)
for tag in (seq $tags_per)
set -l actual_tag (math $tag + $offset)
hc keybind $hlwm_mod-$tag use_index (math $actual_tag-1)
hc keybind $hlwm_mod-Shift-$tag move_index (math $actual_tag-1)
hc keybind $hlwm_mod-$tag use_index \
(math $actual_tag - 1)
hc keybind $hlwm_mod-Shift-$tag move_index \
(math $actual_tag - 1)
end
end

View File

@ -1,19 +0,0 @@
#!/usr/bin/env fish
import parent
# calls logger with a specific color
#
# examples:
#
# log "hello there"
# log -c magenta "im berry"
# log --color cc00cc "just like the blueberries"
function log
set -f log_name (parent)
argparse 'c/color=' -- $argv
if not set -q _flag_color;
set -g _flag_color green
end
echo -s "[ " (set_color $_flag_color) $log_name (set_color normal) " ]: $argv" 1>&2
end

View File

@ -1,24 +1,29 @@
#!/usr/bin/env fish
import colors
import log
set_default notify_fg (hlwm_text)
set_default notify_bg (hlwm_normal)
set_default notify_font $hlwm_font
set_default notify_padding 30
import config
function notify
argparse -i 'secs=!_validate_int --min 1' -- $argv
argparse -i 'fg=' \
'bg=' \
'f/font=' \
'p/padding=' \
'secs=!_validate_int --min 1' \
-- $argv
set_default _flag_fg (get_config NotifyTextColor)
set_default _flag_bg (get_config NotifyBgColor)
set_default _flag_font (get_config Font)
set_default _flag_padding 30
set_default _flag_secs 1
set -f text_width (textwidth "$notify_font" "$argv")
echo "$argv" | \
dzen2 \
-p $_flag_secs \
-fg $notify_fg \
-bg $notify_bg \
-fn $notify_font \
-ta 'c' \
-w (math $text_width + $notify_padding) \
log "using font '$_flag_font'"
set -f text_width (textwidth "$_flag_font" "$argv")
echo "$argv" | \
dzen2 \
-p $_flag_secs \
-fg $_flag_fg \
-bg $_flag_bg \
-fn $_flag_font \
-ta 'c' \
-w (math $text_width + $_flag_padding) \
-h 16
end

View File

@ -1,27 +0,0 @@
#!/usr/bin/env fish
# parent prints the parent script's filename
function parent
set -f trace (status stack-trace)
# By index:
# 1: in command substitution
# 2: parent.fish line
# 3: in function 'parent'
# 4: caller import line
# 5: in command substitution
# 6: caller "parent" invokation line
# 7: in function calling parent
# 8: jackpot! here's the parent of the caller
set -f parent_line $trace[8]
set -f parent_split (string split 'of file' $parent_line)
set -f parent (string trim $parent_split[2])
# Clean up the parent a lil bit
set -f parent (realpath (string replace '~' "$HOME" $parent))
set -f parent_parts (string split '/' $parent)
set -f parent (string join '/' $parent_parts[-1])
# remove .fish suffix
set -f parent (string replace '.fish' '' $parent)
echo $parent
end

View File

@ -0,0 +1,19 @@
#!/usr/bin/env fish
function remove_default
set -f default_tag ( \
hc get_attr tags.by-name.default.index \
&> /dev/null \
)
if test -z "$default_tag"
return 0
end
if test \
"$(hc get_attr tags.focus.index)" = \
"$default_tag"
# switch from default tag
hc use_index 1
end
hc merge_tag "default"
log "removed"
end

View File

@ -1,6 +1,4 @@
#!/usr/bin/env fish
import log
alias hc=herbstclient
function restart_svcs

View File

@ -2,6 +2,8 @@
import fish_functions/notify
import fish_functions/restart_svcs
import fish_functions/group
import fish_functions/config
import fish_functions/remove_default
set -g THIS_PATH (pwd)
log "starting in $THIS_PATH"
@ -10,6 +12,7 @@ alias hc=herbstclient
# default font if not set
set_default hlwm_font "-*-fixed-medium-*-*-*-12-*-*-*-*-*-*-*"
new_config -n Font -v "$hlwm_font"
hc emit_hook reload
if command -sq "xsetroot";
@ -22,18 +25,21 @@ group_active_reset
set -g Mod Mod4
set -g AltMod Mod1
set -u hlwm_mod $Mod
new_config ModKey $Mod
set -U hlwm_mod $Mod
function key
log "Registering $Mod-$argv[1] to [$argv[2..]]"
hc keybind $Mod-$argv[1] $argv[2..]
end
set_default hlwm_terminal_spawn_key "Home"
hc keybind $Mod-Shift-r reload
hc keybind $Mod-Shift-c close
hc keybind $Mod-s spawn "flameshot" gui
hc keybind $Mod-Return spawn "dmenu_run"
hc keybind $Mod-Home spawn "alacritty"
hc keybind $Mod-$hlwm_terminal_spawn_key spawn "alacritty"
# basic movement in tiling and floating mode
# focusing clients
@ -62,8 +68,15 @@ hc keybind $Mod-Control-Down resize down +$resize_step
hc keybind $Mod-Control-Up resize up +$resize_step
hc keybind $Mod-Control-Right resize right +$resize_step
set_default -u hlwm_tags_per_group 5
set_default -u hlwm_group_count 3
set_default hlwm_tags_per_group 5
set_default hlwm_group_count 3
new_config -n GroupCount \
-v $hlwm_group_count \
-t uint
new_config -n TagsPerGroup \
-v $hlwm_tags_per_group \
-t uint
log "registering $hlwm_group_count groups, with $hlwm_tags_per_group tags per"
set -l tag_indexes (seq $hlwm_tags_per_group)
@ -75,16 +88,8 @@ for group_num in (seq $hlwm_group_count)
end
end
# Remove the default tag, if present (switching to the first tag)
if set -l default_tag (hc get_attr tags.by-name.default.index)
set -l focused_tag (hc get_attr tags.focus.index)
if test $focused_tag -eq $default_tag
hc use_index 1
end
hc merge_tag "default"
log "removed default tag from index [$default_tag]"
end
# Remove the default tag
remove_default
group_set_keybinds
# focus
@ -162,6 +167,11 @@ hct urgent.inner_color $URGENT
hct title_color white
hct normal.title_color '#898989'
new_config -n NotifyTextColor \
-v (hc attr theme.normal.title_color)
new_config -n NotifyBgColor -v $NORMAL
for state in active urgent normal
hc substitute C theme.$state.inner_color \
attr theme.$state.outer_color C
@ -206,7 +216,6 @@ end
log "Registering custom command binds"
keybind_fn i "toggle_idle_screen"
keybind_fn --direct="switch_group" "grave" "+" # backtick
keybind_fn --direct="switch_group" "Tab-grave" "-"
for group_index in (seq $hlwm_group_count)
keybind_fn --direct="switch_group" "F$group_index" "$group_index"
end

View File

@ -1,3 +0,0 @@
# hlwm conf todo
- [ ] use hlwm attrs (new_attr in herbstluftwm(1)) rather than fish env