Migrate custom dmenu scripts to writeShellApplication
No longer have all of them as files and apply sed. Instead define dependencies via nix expression. Also allow to write the scripts within nix expression. Some are still large and separate .sh files, but loaded within expression. Also only the main file is exposed as others are only dependencies. Still all can now be installed as all are separate derivations. The new writeShellApplication also executes shellcheck as another benefit. And it makes script executable.
This commit is contained in:
parent
9b435f36c9
commit
9de6cdb3eb
|
@ -1,20 +1,183 @@
|
|||
self: super: {
|
||||
dmenu-custom-scripts = super.stdenv.mkDerivation {
|
||||
name = "dmenu-custom-scripts";
|
||||
|
||||
src = ./src;
|
||||
# Still has many references to Ubuntu system tools.
|
||||
# Will migrate step by step and update references.
|
||||
|
||||
# For now it is cool to have a first custom package which can be installed.
|
||||
|
||||
# It already uses nix dunst and dmenu.
|
||||
# Also things like version switch should not be necessary once I managed nix shells.
|
||||
|
||||
buildPhase = ''
|
||||
mkdir -p "$out/bin"
|
||||
dmenu-custom-scripts-calc = super.pkgs.writeShellApplication {
|
||||
name = "dmenu-custom-scripts-calc";
|
||||
|
||||
runtimeInputs = [
|
||||
super.pkgs.dmenu
|
||||
super.pkgs.bc
|
||||
];
|
||||
|
||||
text = ''
|
||||
input=$(dmenu -i)
|
||||
result=$(echo "$input" | scale=4 bc -l)
|
||||
echo "$result" | dmenu -i -p "Result:"
|
||||
'';
|
||||
};
|
||||
|
||||
installPhase = ''
|
||||
declare -xp
|
||||
cp -r * "$out/bin/"
|
||||
sed -i 's#\$dmenu#${super.pkgs.dmenu}/bin/dmenu#' $out/bin/dmenu_selection
|
||||
sed -i "s#\$out#$out/bin#" $out/bin/dmenu_selection
|
||||
sed -i 's#\$dmenu#${super.pkgs.dmenu}/bin/dmenu#' $out/bin/scripts/*
|
||||
sed -i 's#\$dunstctl#${super.pkgs.dunst}/bin/dunstctl#' $out/bin/scripts/*
|
||||
dmenu-custom-scripts-notifications = super.pkgs.writeShellApplication {
|
||||
name = "dmenu-custom-scripts-notifications";
|
||||
|
||||
runtimeInputs = [
|
||||
super.pkgs.dmenu
|
||||
super.pkgs.dunst
|
||||
];
|
||||
|
||||
text = ''
|
||||
chosen=$(echo -e "pause\nresume" | dmenu -i)
|
||||
case "$chosen" in
|
||||
"pause")
|
||||
dunstctl set-paused true
|
||||
;;
|
||||
"resume")
|
||||
dunstctl set-paused false
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
'';
|
||||
};
|
||||
|
||||
dmenu-custom-scripts-system = super.pkgs.writeShellApplication {
|
||||
name = "dmenu-custom-scripts-system";
|
||||
|
||||
runtimeInputs = [
|
||||
super.pkgs.dmenu
|
||||
super.pkgs.dunst
|
||||
];
|
||||
|
||||
text = builtins.readFile ./system.sh;
|
||||
};
|
||||
|
||||
dmenu-custom-scripts-docs-php = super.pkgs.writeShellApplication {
|
||||
name = "dmenu-custom-scripts-docs-php";
|
||||
|
||||
runtimeInputs = [
|
||||
super.pkgs.dmenu
|
||||
];
|
||||
|
||||
text = ''
|
||||
file=$(find ~/Projects/docs/php/ -maxdepth 1 -name '*.html' -printf "%f\n" | dmenu -i -l 20 -p "Search Term")
|
||||
firefox --new-tab "http://php.docs.localhost/$file"
|
||||
'';
|
||||
};
|
||||
|
||||
dmenu-custom-scripts-php-version = super.pkgs.writeShellApplication {
|
||||
name = "dmenu-custom-scripts-php-version";
|
||||
|
||||
runtimeInputs = [
|
||||
super.pkgs.dmenu
|
||||
];
|
||||
|
||||
text = ''
|
||||
chosen=$(update-alternatives --list php | dmenu -i -l 20 -p "$(php --version | head -1 | cut -d' ' -f2 | cut -d'.' -f1,2)")
|
||||
sudo update-alternatives --set php "$chosen" > /dev/null
|
||||
pkill -SIGRTMIN+10 i3blocks
|
||||
notify-send "switching php version" "$(php --version)"
|
||||
'';
|
||||
};
|
||||
|
||||
dmenu-custom-scripts-composer-version = super.pkgs.writeShellApplication {
|
||||
name = "dmenu-custom-scripts-composer-version";
|
||||
|
||||
runtimeInputs = [
|
||||
super.pkgs.dmenu
|
||||
];
|
||||
|
||||
text = ''
|
||||
chosen=$(echo -e "1\n2\n"| dmenu -i -l 20 -p "$(composer --version)")
|
||||
composer selfupdate --"$chosen"
|
||||
pkill -SIGRTMIN+10 i3blocks
|
||||
notify-send "switching composer version" "$(composer --version)"
|
||||
'';
|
||||
};
|
||||
|
||||
dmenu-custom-scripts-xdebug = super.pkgs.writeShellApplication {
|
||||
name = "dmenu-custom-scripts-xdebug";
|
||||
|
||||
runtimeInputs = [
|
||||
super.pkgs.dmenu
|
||||
];
|
||||
|
||||
text = builtins.readFile ./xdebug.sh;
|
||||
};
|
||||
|
||||
dmenu-custom-scripts-node-version = super.pkgs.writeShellApplication {
|
||||
name = "dmenu-custom-scripts-node-version";
|
||||
|
||||
runtimeInputs = [
|
||||
super.pkgs.dmenu
|
||||
];
|
||||
|
||||
text = ''
|
||||
nodechosen=$(update-alternatives --list node | dmenu -i -l 20 -p "$(node --version | cut -d'.' -f1,2 | sed s/v//)")
|
||||
npmchoosen="$(dirname "$(dirname "$nodechosen")")/lib/node_modules"
|
||||
sudo update-alternatives --set node "$nodechosen" > /dev/null
|
||||
sudo update-alternatives --set npm "$npmchoosen" > /dev/null
|
||||
pkill -SIGRTMIN+10 i3blocks
|
||||
notify-send "switching node version" "$(node --version)"
|
||||
'';
|
||||
};
|
||||
|
||||
dmenu-custom-scripts = super.pkgs.writeShellApplication rec {
|
||||
name = "dmenu_selection";
|
||||
|
||||
# TODO: Find way to remove the nix prefixes from "files"
|
||||
text = ''
|
||||
scripts=()
|
||||
scripts+=("${super.pkgs.dmenu-custom-scripts-calc.name}")
|
||||
scripts+=("${super.pkgs.dmenu-custom-scripts-notifications.name}")
|
||||
scripts+=("${super.pkgs.dmenu-custom-scripts-system.name}")
|
||||
scripts+=("${super.pkgs.dmenu-custom-scripts-docs-php.name}")
|
||||
scripts+=("${super.pkgs.dmenu-custom-scripts-php-version.name}")
|
||||
scripts+=("${super.pkgs.dmenu-custom-scripts-composer-version.name}")
|
||||
scripts+=("${super.pkgs.dmenu-custom-scripts-xdebug.name}")
|
||||
scripts+=("${super.pkgs.dmenu-custom-scripts-node-version.name}")
|
||||
|
||||
OIFS="$IFS" IFS=$'\n'
|
||||
scriptsString="''${scripts[*]}"
|
||||
IFS="$OIFS"
|
||||
|
||||
action=$(echo -e "$scriptsString" | dmenu -i -l 20)
|
||||
|
||||
case "$action" in
|
||||
"${super.pkgs.dmenu-custom-scripts-calc.name}")
|
||||
bash "${super.pkgs.dmenu-custom-scripts-calc}/bin/${super.pkgs.dmenu-custom-scripts-calc.name}" || exit 0
|
||||
;;
|
||||
"${super.pkgs.dmenu-custom-scripts-notifications.name}")
|
||||
bash "${super.pkgs.dmenu-custom-scripts-notifications}/bin/${super.pkgs.dmenu-custom-scripts-notifications.name}" || exit 0
|
||||
;;
|
||||
"${super.pkgs.dmenu-custom-scripts-system.name}")
|
||||
bash "${super.pkgs.dmenu-custom-scripts-system}/bin/${super.pkgs.dmenu-custom-scripts-system.name}" || exit 0
|
||||
;;
|
||||
"${super.pkgs.dmenu-custom-scripts-docs-php.name}")
|
||||
bash "${super.pkgs.dmenu-custom-scripts-docs-php}/bin/${super.pkgs.dmenu-custom-scripts-docs-php.name}" || exit 0
|
||||
;;
|
||||
"${super.pkgs.dmenu-custom-scripts-php-version.name}")
|
||||
bash "${super.pkgs.dmenu-custom-scripts-php-version}/bin/${super.pkgs.dmenu-custom-scripts-php-version.name}" || exit 0
|
||||
;;
|
||||
"${super.pkgs.dmenu-custom-scripts-composer-version.name}")
|
||||
bash "${super.pkgs.dmenu-custom-scripts-composer-version}/bin/${super.pkgs.dmenu-custom-scripts-composer-version.name}" || exit 0
|
||||
;;
|
||||
"${super.pkgs.dmenu-custom-scripts-xdebug.name}")
|
||||
bash "${super.pkgs.dmenu-custom-scripts-xdebug}/bin/${super.pkgs.dmenu-custom-scripts-xdebug.name}" || exit 0
|
||||
;;
|
||||
"${super.pkgs.dmenu-custom-scripts-node-version.name}")
|
||||
bash "${super.pkgs.dmenu-custom-scripts-node-version}/bin/${super.pkgs.dmenu-custom-scripts-node-version.name}" || exit 0
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
Still has many references to Ubuntu system tools.
|
||||
Will migrate step by step and update references.
|
||||
|
||||
For now it is cool to have a first custom package which can be installed.
|
||||
|
||||
It already uses nix dunst and dmenu.
|
|
@ -1,10 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
pushd "$out/scripts"
|
||||
|
||||
# use "." for files in folder, use "*" for subfolder as well
|
||||
chosen=$(ls -1 . | $dmenu -i -l 20)
|
||||
|
||||
popd
|
||||
|
||||
sh "$out/scripts/$chosen" || exit 0
|
|
@ -1,5 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
input=$($dmenu -i)
|
||||
result=$(echo $input | scale=4 bc -l)
|
||||
echo $result | $dmenu -i -p "Result:"
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
chosen=$(echo "1\n2\n"| $dmenu -i -l 20 -p "$(composer --version)")
|
||||
composer selfupdate --$chosen
|
||||
pkill -SIGRTMIN+10 i3blocks
|
||||
notify-send "switching composer version" "$(composer --version)"
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
file=$(ls ~/Projects/docs/php/ | $dmenu -i -l 20 -p "Search Term")
|
||||
firefox --new-tab http://php.docs.localhost/$file
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
nodechosen=$(update-alternatives --list node | $dmenu -i -l 20 -p "$(node --version | cut -d'.' -f1,2 | sed s/v//)")
|
||||
npmchoosen="$(dirname $(dirname $nodechosen))/lib/node_modules"
|
||||
sudo update-alternatives --set node $nodechosen > /dev/null
|
||||
sudo update-alternatives --set npm $npmchoosen > /dev/null
|
||||
pkill -SIGRTMIN+10 i3blocks
|
|
@ -1,14 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
chosen=$(echo "pause\nresume" | $dmenu -i)
|
||||
case "$chosen" in
|
||||
"pause")
|
||||
$dunstctl set-paused true
|
||||
;;
|
||||
"resume")
|
||||
$dunstctl set-paused false
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
chosen=$(update-alternatives --list php | $dmenu -i -l 20 -p "$(php --version | head -1 | cut -d' ' -f2 | cut -d'.' -f1,2)")
|
||||
sudo update-alternatives --set php $chosen > /dev/null
|
||||
pkill -SIGRTMIN+10 i3blocks
|
||||
notify-send "switching php version" "$(php --version)"
|
|
@ -1,63 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
activeString=""
|
||||
action=$(echo "enable\ndisable\n" | $dmenu -i -p "$activeString")
|
||||
case "$action" in
|
||||
"enable")
|
||||
sudo /bin/ln -s /etc/php/5.6/mods-available/xdebug.ini /etc/php/5.6/cli/conf.d/20-xdebug.ini
|
||||
sudo /bin/ln -s /etc/php/5.6/mods-available/xdebug.ini /etc/php/5.6/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini
|
||||
sudo /bin/ln -s /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.1/mods-available/xdebug.ini /etc/php/7.1/cli/conf.d/20-xdebug.ini
|
||||
sudo /bin/ln -s /etc/php/7.1/mods-available/xdebug.ini /etc/php/7.1/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.2/mods-available/xdebug.ini /etc/php/7.2/cli/conf.d/20-xdebug.ini
|
||||
sudo /bin/ln -s /etc/php/7.2/mods-available/xdebug.ini /etc/php/7.2/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.3/mods-available/xdebug.ini /etc/php/7.3/cli/conf.d/20-xdebug.ini
|
||||
sudo /bin/ln -s /etc/php/7.3/mods-available/xdebug.ini /etc/php/7.3/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.4/mods-available/xdebug.ini /etc/php/7.4/cli/conf.d/20-xdebug.ini
|
||||
sudo /bin/ln -s /etc/php/7.4/mods-available/xdebug.ini /etc/php/7.4/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /bin/ln -s /etc/php/8.0/mods-available/xdebug.ini /etc/php/8.0/cli/conf.d/20-xdebug.ini
|
||||
sudo /bin/ln -s /etc/php/8.0/mods-available/xdebug.ini /etc/php/8.0/fpm/conf.d/20-xdebug.ini
|
||||
;;
|
||||
"disable")
|
||||
sudo /usr/bin/unlink /etc/php/5.6/cli/conf.d/20-xdebug.ini
|
||||
sudo /usr/bin/unlink /etc/php/5.6/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.0/cli/conf.d/20-xdebug.ini
|
||||
sudo /usr/bin/unlink /etc/php/7.0/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.1/cli/conf.d/20-xdebug.ini
|
||||
sudo /usr/bin/unlink /etc/php/7.1/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.2/cli/conf.d/20-xdebug.ini
|
||||
sudo /usr/bin/unlink /etc/php/7.2/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.3/cli/conf.d/20-xdebug.ini
|
||||
sudo /usr/bin/unlink /etc/php/7.3/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.4/cli/conf.d/20-xdebug.ini
|
||||
sudo /usr/bin/unlink /etc/php/7.4/fpm/conf.d/20-xdebug.ini
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/8.0/cli/conf.d/20-xdebug.ini
|
||||
sudo /usr/bin/unlink /etc/php/8.0/fpm/conf.d/20-xdebug.ini
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
sudo /bin/systemctl reload php5.6-fpm.service
|
||||
sudo /bin/systemctl reload php7.0-fpm.service
|
||||
sudo /bin/systemctl reload php7.1-fpm.service
|
||||
sudo /bin/systemctl reload php7.2-fpm.service
|
||||
sudo /bin/systemctl reload php7.3-fpm.service
|
||||
sudo /bin/systemctl reload php7.4-fpm.service
|
||||
sudo /bin/systemctl reload php8.0-fpm.service
|
||||
pkill -SIGRTMIN+10 i3blocks
|
||||
notify-send "switching xdebug: $action"
|
2
overlays/dmenu-custom-scripts/src/scripts/system → overlays/dmenu-custom-scripts/system.sh
Executable file → Normal file
2
overlays/dmenu-custom-scripts/src/scripts/system → overlays/dmenu-custom-scripts/system.sh
Executable file → Normal file
|
@ -4,7 +4,7 @@
|
|||
# TODO: Stop all software before logout
|
||||
# https://faq.i3wm.org/question/239/how-do-i-suspendlockscreen-and-logout.1.html#post-id-1927
|
||||
|
||||
chosen=$(echo "lock\nsuspend\nlogout" | $dmenu -i)
|
||||
chosen=$(echo -e "lock\nsuspend\nlogout" | dmenu -i)
|
||||
case "$chosen" in
|
||||
"lock")
|
||||
# See: https://faq.i3wm.org/question/5654/how-can-i-disable-notifications-when-the-screen-locks-and-enable-them-again-when-unlocking/index.html#post-id-5655
|
58
overlays/dmenu-custom-scripts/xdebug.sh
Normal file
58
overlays/dmenu-custom-scripts/xdebug.sh
Normal file
|
@ -0,0 +1,58 @@
|
|||
activeString=""
|
||||
action=$(echo -e "enable\ndisable\n" | dmenu -i -p "$activeString")
|
||||
case "$action" in
|
||||
"enable")
|
||||
sudo /bin/ln -s /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /bin/ln -s /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.1/mods-available/xdebug.ini /etc/php/7.1/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /bin/ln -s /etc/php/7.1/mods-available/xdebug.ini /etc/php/7.1/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.2/mods-available/xdebug.ini /etc/php/7.2/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /bin/ln -s /etc/php/7.2/mods-available/xdebug.ini /etc/php/7.2/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.3/mods-available/xdebug.ini /etc/php/7.3/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /bin/ln -s /etc/php/7.3/mods-available/xdebug.ini /etc/php/7.3/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /bin/ln -s /etc/php/7.4/mods-available/xdebug.ini /etc/php/7.4/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /bin/ln -s /etc/php/7.4/mods-available/xdebug.ini /etc/php/7.4/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /bin/ln -s /etc/php/8.0/mods-available/xdebug.ini /etc/php/8.0/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /bin/ln -s /etc/php/8.0/mods-available/xdebug.ini /etc/php/8.0/fpm/conf.d/20-xdebug.ini || true
|
||||
;;
|
||||
"disable")
|
||||
sudo /usr/bin/unlink /etc/php/7.0/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /usr/bin/unlink /etc/php/7.0/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.1/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /usr/bin/unlink /etc/php/7.1/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.2/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /usr/bin/unlink /etc/php/7.2/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.3/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /usr/bin/unlink /etc/php/7.3/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/7.4/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /usr/bin/unlink /etc/php/7.4/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/8.0/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /usr/bin/unlink /etc/php/8.0/fpm/conf.d/20-xdebug.ini || true
|
||||
|
||||
sudo /usr/bin/unlink /etc/php/8.1/cli/conf.d/20-xdebug.ini || true
|
||||
sudo /usr/bin/unlink /etc/php/8.1/fpm/conf.d/20-xdebug.ini || true
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
sudo /bin/systemctl reload php7.0-fpm.service || true
|
||||
sudo /bin/systemctl reload php7.1-fpm.service || true
|
||||
sudo /bin/systemctl reload php7.2-fpm.service || true
|
||||
sudo /bin/systemctl reload php7.3-fpm.service || true
|
||||
sudo /bin/systemctl reload php7.4-fpm.service || true
|
||||
sudo /bin/systemctl reload php8.0-fpm.service || true
|
||||
sudo /bin/systemctl reload php8.1-fpm.service || true
|
||||
pkill -SIGRTMIN+10 i3blocks || true
|
||||
notify-send "switching xdebug: $action"
|
Loading…
Reference in a new issue