added menu-qalc

This commit is contained in:
Schrottkatze 2022-09-02 20:28:50 +02:00
parent e4b15a3b1a
commit bce7db5f8d
11 changed files with 180 additions and 76 deletions

View file

@ -107,6 +107,7 @@ with builtins;
fzf openrgb krita gimp inkscape blender virglrenderer ddccontrol-db
glab firebird-emu
discord
# experimental
];
environment.pathsToLink = [

View file

@ -2,17 +2,15 @@
description = "home manager config apparently";
inputs = {
# nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
nixpkgs.url = "github:kekrby/nixpkgs/add-fetchpartial";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpks.follows = "nixpkgs";
};
nixos-hardware.url = "github:kekrby/nixos-hardware";
# nixpkgs-fetchpartial.url = "github:kekrby/nixpkgs";
};
outputs = { self, nixpkgs, home-manager, nixos-hardware, ... }: {
outputs = { self, nixpkgs, home-manager, nixos-hardware,... }: {
nixosConfigurations = {
monosodium-glutamate-g = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";

View file

@ -2,71 +2,14 @@
let
cfg = config.jade.desktop;
# Screenshot scripts {{{
window-screenshot = pkgs.writeShellScriptBin "window-screenshot.sh" ''
unset x y w h
eval $(xwininfo -id $(xdotool getactivewindow) |
sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
-e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
-e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
-e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
echo -n "''$x ''$y ''$w ''$h"
flameshot gui --region "''${w}x''${h}+''${x}+''${y}" -c -p ~/Pictures/screenshots/
'';
# }}}
# Desktop ctl {{{
desktop-ctl = pkgs.writeShellScriptBin "desktop-ctl.sh" ''
items="lock screen;log out;toggle picom;shut down;reboot;update all"
selection=$(echo $items | rofi -sep ";" -dmenu)
case $selection in
"lock screen")
i3lock-fancy
;;
"log out")
pkill i3
;;
"toggle picom")
pkill picom || picom --experimental-backend -b
;;
"shut down")
shutdown now
;;
"reboot")
systemctl reboot
;;
esac
'';
# }}}
# Macro scripts {{{
em-record = pkgs.writeShellScriptBin "em-record.sh" ''
register=$(ls $HOME/xmacros | rofi -dmenu)
count=$(echo "2;5;10;20;50;100" | rofi -dmenu -sep ";" -l 5)
for i in $(seq $count); do
echo $i
xmacroplay "$DISPLAY" < $HOME/xmacros/$register
done
register=$(ls $HOME/xmacros | rofi -dmenu)
xmacrorec2 > $HOME/xmacros/$register
'';
em-play = pkgs.writeShellScriptBin "em-play.sh" ''
register=$(ls $HOME/xmacros | rofi -dmenu)
xmacroplay "$DISPLAY" < $HOME/xmacros/$register
'';
em-play-loop = pkgs.writeShellScriptBin "em-play-loop.sh" ''
register=$(ls $HOME/xmacros | rofi -dmenu)
count=$(echo "2;5;10;20;50;100" | rofi -dmenu -sep ";" -l 5)
for i in $(seq $count); do
echo $i
xmacroplay "$DISPLAY" < $HOME/xmacros/$register
done
'';
# }}}
window-screenshot = pkgs.writeShellScriptBin "window-screenshot.sh" (builtins.readFile ../scripts/desktop/window-screenshot.sh);
desktop-ctl = pkgs.writeShellScriptBin "desktop-ctl.sh" (builtins.readFile ../scripts/desktop/desktop-ctl.sh);
em-record = pkgs.writeShellScriptBin "em-record.sh" (builtins.readFile ../scripts/desktop/macros/record.sh);
em-play = pkgs.writeShellScriptBin "em-play.sh" (builtins.readFile ../scripts/desktop/macros/play.sh);
em-play-loop = pkgs.writeShellScriptBin "em-play-loop.sh" (builtins.readFile ../scripts/desktop/macros/play-loop.sh);
ocr-screenshot = pkgs.writeShellScriptBin "ocr-screenshot.sh" (builtins.readFile ../scripts/desktop/ocr-screenshot.sh);
# rofi calculator copied from https://github.com/barbuk/menu-qalc
menu-qalc = pkgs.writeShellScriptBin "menu-qalc" (builtins.readFile ../scripts/desktop/menu-qalc.sh);
in with lib; {
options.jade.desktop = {
enable = mkEnableOption "Enable the i3 setup";
@ -79,12 +22,13 @@ in with lib; {
i3lock-fancy rofi rofimoji volumeicon feh xorg.xinput dunst
arandr lxappearance gruvbox-dark-gtk gruvbox-dark-icons-gtk
gruvterial-theme flameshot tesseract5 imagemagick xclip polybar kitty
xkeysnail gtk-engine-murrine playerctl xmacro
xkeysnail gtk-engine-murrine playerctl xmacro pa_applet brightnessctl
libqalculate # needed by menu-qalc
# custom scripts
window-screenshot desktop-ctl em-record em-play em-play-loop
pa_applet
brightnessctl gruvbox-dark-icons-gtk
gruvbox-dark-gtk
window-screenshot desktop-ctl em-record em-play em-play-loop ocr-screenshot menu-qalc
# themes
gruvbox-dark-gtk gruvbox-dark-icons-gtk
];
# i3 {{{
xsession = {
@ -162,13 +106,13 @@ in with lib; {
"${mod}+w" = "exec window-screenshot.sh";
"${mod}+s" = "exec flameshot gui -c -p $HOME/Pictures/screenshots";
"${mod}+a" = "exec flameshot screen -c -p $HOME/Pictures/screenshots";
"${mod}+t" = "exec ocr-screenshot.sh";
# rofi fuckery
"${mod}+d" = "exec --no-startup-id rofi -show drun";
"${mod}+space" = "exec --no-startup-id -show window";
"${mod}+i" = "exec --no-startup-id rofimoji -f alchemical_symbols emojis braille_patterns box_drawing chess_symbols emoticons geometric_shapes gothic greek_extended math mathematical_alphanumeric_symbols mathematical_operators miscellaneous_symbols miscellaneous_mathematical_symbols-a miscellaneous_mathematical_symbols-b miscellaneous_symbols_and_arrows miscellaneous_symbols_and_pictographs miscellaneous_technical modi modifier_tone_letters musical_symbols nerd_font number_forms shorthand_format_controls specials variation_selectors vertical_forms -a copy";
"${mod}+Shift+e" = "exec --no-startup-id desktop-ctl.sh";
# rofi calculator, https://github.com/barbuk/menu-qalc
# "${mod}+m" = "exec --no-startup-id ="
"${mod}+m" = "exec --no-startup-id menu-qalc";
# audio
"XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +10% && $refresh_i3status";

View file

@ -0,0 +1,21 @@
items="lock screen;log out;toggle picom;shut down;reboot;update all"
selection=$(echo $items | rofi -sep ";" -dmenu)
case $selection in
"lock screen")
i3lock-fancy
;;
"log out")
pkill i3
;;
"toggle picom")
pkill picom || picom --experimental-backend -b
;;
"shut down")
shutdown now
;;
"reboot")
systemctl reboot
;;
esac

View file

@ -0,0 +1,7 @@
register=$(ls $HOME/xmacros | rofi -dmenu)
count=$(echo "2;5;10;20;50;100" | rofi -dmenu -sep ";" -l 5)
for i in $(seq $count); do
echo $i
xmacroplay "$DISPLAY" < $HOME/xmacros/$register
done

View file

@ -0,0 +1,3 @@
register=$(ls $HOME/xmacros | rofi -dmenu)
xmacroplay "$DISPLAY" < $HOME/xmacros/$register

View file

@ -0,0 +1,10 @@
register=$(ls $HOME/xmacros | rofi -dmenu)
count=$(echo "2;5;10;20;50;100" | rofi -dmenu -sep ";" -l 5)
for i in $(seq $count); do
echo $i
xmacroplay "$DISPLAY" < $HOME/xmacros/$register
done
register=$(ls $HOME/xmacros | rofi -dmenu)
xmacrorec2 > $HOME/xmacros/$register

View file

@ -0,0 +1,87 @@
# Copy-pasted from https://raw.githubusercontent.com/BarbUk/menu-qalc/master/%3D
# I hope this is even legal but OH WELL
# https://github.com/onespaceman/menu-calc
# Calculator for use with rofi/dmenu(2)
# Copying to the clipboard requires xclip
usage() {
echo "$(tput bold)menu-calc$(tput sgr0)"
echo "A calculator for Rofi/dmenu(2)"
echo
echo "$(tput bold)Usage:$(tput sgr0)"
echo " = 4+2"
echo " = (4+2)/(4+3)"
echo " = 4^2"
echo " = sqrt(4)"
echo " = c(2)"
echo
echo "$(tput bold)Force Rofi/dmenu(2):$(tput sgr0)"
echo "By default, if rofi exists, it will be used. To force menu-calc to"
echo "use one or the other, use the --dmenu argument"
echo
echo " = --dmenu=<dmenu_executable>"
echo
echo "$(tput bold)Passing arguments to Rofi/dmenu(2):$(tput sgr0)"
echo "Any parameters after ' -- ' will be passed to Rofi/dmenu(2)."
echo
echo " = -- <Rofi/dmenu(2) args>"
echo
echo "The answer can be copied to the clipboard and used for further calculations inside (or outside) Rofi/dmenu."
echo
echo "If launched outside of Rofi/dmenu the expression may need quotation marks."
exit
}
# Process CLI parameters
for var in "$@"
do
case $var in
-h|--help) usage ;;
-d=*|--dmenu=*)
menu=$(echo $var | cut -d'=' -f 2);
;;
--) break ;;
esac
done
# Grab the answer
if [ -n "$1" ]; then
answer=$(echo "$1" | qalc +u8 -color=never -terse | awk '!/^>/ && !/^$/ {gsub(/^[ \t]+|[ \t]+$/, "", $0); print}')
fi
# Path to menu application
if [ -z "${menu+1}" ]; then
if [[ -n $(command -v rofi) ]]; then
menu="$(command -v rofi)"
elif [[ -n $(command -v dmenu) ]]; then
menu=$(command -v dmenu)
else
>&2 echo "Rofi or dmenu not found"
exit
fi
fi
# If using rofi, add the necessary parameters
if [[ $menu == "rofi" || $menu == $(command -v rofi) ]]; then
menu="$menu -dmenu -lines 3"
elif [[ $menu == "dmenu" || $menu == $(command -v dmenu) ]]; then
menu="$menu ""$DMENU_OPTIONS"
fi
# Determine args to pass to dmenu/rofi
while [[ $# -gt 0 && $1 != "--" ]]; do
shift
done
[[ $1 == "--" ]] && shift
action=$(echo -e "Copy to clipboard\nClear\nClose" | $menu "$@" -p "= $answer")
case $action in
"Clear") $0 ;;
"Copy to clipboard") echo -n "$answer" | xclip -selection clipboard ;;
"Close") ;;
"") ;;
*) $0 "$answer $action" "--dmenu=$menu" "--" "$@" ;;
esac

View file

@ -0,0 +1,26 @@
langs="eng deu spa osd"
langs=$(tesseract --list-langs | tail +2)
first_menu="$langs exit"
selection_menu1=$(echo $first_menu | rofi -sep " " -dmenu)
tmp_img=`mktemp`
trap "rm $tmp_img*" EXIT
echo $selection_menu1
case $selection_menu1 in
"eng"|"deu"|"spa"|"osd"|"fra")
tesseract_lang=$selection_menu1
flameshot gui -p $tmp_img.png -d 100
mogrify -modulate 100,0 -resize 400% $tmp_img.png
;;
"exit")
exit
;;
esac
tesseract $tmp_img.png $tmp_img &> /dev/null
xclip -i $tmp_img.txt -selection clipboard
exit

View file

@ -0,0 +1,8 @@
unset x y w h
eval $(xwininfo -id $(xdotool getactivewindow) |
sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
-e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
-e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
-e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
echo -n "''$x ''$y ''$w ''$h"
flameshot gui --region "''${w}x''${h}+''${x}+''${y}" -c -p ~/Pictures/screenshots/

View file

@ -1 +0,0 @@
with import <nixpkgs> {};