don't wrap shell scripts in nix file

This commit is contained in:
Leonardo Eugênio 2022-10-18 12:37:14 -03:00
parent cdcdc90a10
commit 5422aea875
5 changed files with 147 additions and 52 deletions

61
scripts/bmenu Normal file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env fish
# wrapper around bemenu
# bmenu * - use as dmenu, -p for custom prompt (man bemenu)
# bmenu run - select from .desktop files and run it
# bmenu start - internal option
if test "$argv[1]" = "run"
test -n "$argv[2]" && set t "$argv[2]" || set t "terminal"
test -n "$i3SOCK" && set wrapper 'i3-msg exec --'
test -n "$SWAYSOCK" && set wrapper 'swaymsg exec --'
exec j4-dmenu-desktop \
--dmenu="bmenu start -p Iniciar:" \
--term "$t" \
--wrapper="$wrapper" \
--no-generic
end
if test -n "$SWAYSOCK"
swaymsg -t get_tree |
jq -je '..|select(.focused? and .fullscreen_mode? == 1)|""' &&
swaymsg -q fullscreen off &&
set fullscreen
swaymsg -t get_outputs |
jq -r 'map(.focused)|reverse|index(true)' |
read focused_output
test -n "$focused_output"
and set focused_output "-m $focused_output"
end
function clean_exit
set -q fullscreen
and swaymsg -q fullscreen on &
end
trap clean_exit EXIT
set -l config "$HOME/.config/bmenu.conf"
if test -f $config
source $config
end
dhist wrap -- bemenu \
$focused_output\
--ignorecase\
--bottom\
--no-overlap\
--list 20\
--prefix '>'\
--fn "$fn"\
--tb "$tb" --tf "$tf" \
--fb "$fb" --ff "$ff" \
--nb "$nb" --nf "$nf" \
--hb "$hb" --hf "$hf" \
$argv
# vim: ft=fish

47
scripts/br Normal file
View file

@ -0,0 +1,47 @@
#!/bin/sh
set -e -u
end(){
rm -r -- "$(dirname -- "$namebase")"
[ $# -ne 0 ] && echo $@ >&2
exit $#
}
if [ $# -ne 0 ] ; then
for i in "$@" ; do
printf "%s\n" "$i"
done | "$0"
exit $?
fi
namebase="$(mktemp -d)/blkrn"
echo '# Modify filenames without removing any line, quitting aborts' \
> "$namebase.2"
tee -- "$namebase.1" >> "$namebase.2"
exec </dev/tty >/dev/tty ||
end 'Interactive terminal needed'
"$EDITOR" -- "$namebase.2"
sed -i -- '1d' "$namebase.2"
! diff -- "$namebase.1" "$namebase.2" &> /dev/null || end "no changes"
[ `wc -l < "$namebase.1"` -eq `wc -l < "$namebase.2"` ] || end "Wrong number of lines"
{
echo '# Please review/modify this script or empty it to do nothing'
echo 'run(){'
echo ' mkdir -p "$(dirname "$2")"'
echo ' mv -T -- "$1" "$2"'
echo '}'
while read -r l1 <&3 && read -r l2 <&4; do
[ "$l1" = "$l2" ] || printf "%s\n%s\n" "$l1" "$l2"
done 3<"$namebase.1" 4<"$namebase.2" |
sed 's/\([\\"$`]\)/\\\1/g;s/^.*$/"&"/' |
xargs -d"\n" -L2 echo 'run'
} > "$namebase.sh"
"$EDITOR" -- "$namebase.sh"
sh -e -- "$namebase.sh"
end # exit normaly

View file

@ -1,48 +0,0 @@
{ config, pkgs, lib, ... }:
pkgs.writeScriptBin "br" ''
set -e -u
end(){
rm -r -- "$(dirname -- "$namebase")"
[ $# -ne 0 ] && echo $@ >&2
exit $#
}
if [ $# -ne 0 ] ; then
for i in "$@" ; do
printf "%s\n" "$i"
done | "$0"
exit $?
fi
namebase="$(mktemp -d)/blkrn"
echo '# Modify filenames without removing any line, quitting aborts' \
> "$namebase.2"
tee -- "$namebase.1" >> "$namebase.2"
exec </dev/tty >/dev/tty ||
end 'Interactive terminal needed'
"$EDITOR" -- "$namebase.2"
sed -i -- '1d' "$namebase.2"
! diff -- "$namebase.1" "$namebase.2" &> /dev/null || end "no changes"
[ `wc -l < "$namebase.1"` -eq `wc -l < "$namebase.2"` ] || end "Wrong number of lines"
{
echo '# Please review/modify this script or empty it to do nothing'
echo 'run(){'
echo ' mkdir -p "$(dirname "$2")"'
echo ' mv -T -- "$1" "$2"'
echo '}'
while read -r l1 <&3 && read -r l2 <&4; do
[ "$l1" = "$l2" ] || printf "%s\n%s\n" "$l1" "$l2"
done 3<"$namebase.1" 4<"$namebase.2" |
sed 's/\([\\"$`]\)/\\\1/g;s/^.*$/"&"/' |
xargs -d"\n" -L2 echo 'run'
} > "$namebase.sh"
"$EDITOR" -- "$namebase.sh"
sh -e -- "$namebase.sh"
end # exit normaly
''

View file

@ -1,15 +1,32 @@
{ config, lib, ... }:
(pkgs: _:
let import_script = (_: path: import (path) { inherit config pkgs lib; });
in lib.mapAttrs import_script {
with pkgs;
let
import_script = (_: path: import (path) { inherit config pkgs lib; });
create_shell_app = (name: text: runtimeInputs: pkgs.writeShellApplication {
inherit name runtimeInputs;
text = (builtins.readFile text);
checkPhase = "";
});
create_shell_apps = lib.mapAttrs (name: deps: create_shell_app name ./${name} deps);
in create_shell_apps {
br = [];
bmenu = [
bemenu
dhist
fish
j4-dmenu-desktop
jq
sway
];
} // lib.mapAttrs import_script {
wdmenu = ./wdmenu.nix;
wlauncher = ./wlauncher.nix;
bmenu = ./bmenu.nix;
# bmenu = ./bmenu.nix;
_diffr = ./diffr.nix;
kak-pager = ./kak-pager.nix;
terminal = ./terminal.nix;
wpass = ./wpass.nix;
screenshotsh = ./screenshotsh.nix;
_gpg-unlock = ./_gpg-unlock.nix;
br = ./br.nix;
})

View file

@ -299,4 +299,22 @@ in {
cache-pause-initial=true;
cache-pause-wait=10;
};
# My bemenu wrapper
xdg.configFile = {
"bmenu.conf".text = ''
set fn "${font.mono} ${toString font.size.small}"
set tb "${color.bg}${theme.opacityHex}"
set tf "${accent.color}"
set fb "${color.bg}${theme.opacityHex}"
set ff "${color.txt}"
set nb "${color.bg}${theme.opacityHex}"
set nf "${color.txt}"
set hb "${accent.color}"
set hf "${accent.fg}"
'';
};
}