From 4660468bd0d40e367562be1914a049cfb1d913a9 Mon Sep 17 00:00:00 2001 From: MoritzBoehme Date: Sun, 26 Dec 2021 23:34:42 +0100 Subject: [PATCH] write Shell Applications using nix --- bin/cheat | 2 - bin/cproton.sh | 122 ------------------------------- bin/cycle_sinks.sh | 19 ----- bin/sup | 9 --- bin/sxhkd-help | 5 -- modules/cli/bin/cheat.nix | 9 +++ modules/cli/bin/cycleSinks.nix | 25 +++++++ modules/cli/bin/default.nix | 11 +++ modules/cli/bin/protonge.nix | 127 +++++++++++++++++++++++++++++++++ modules/cli/bin/sxhkdHelp.nix | 11 +++ modules/cli/default.nix | 2 +- modules/default.nix | 6 -- modules/desktop/bspwm/sxhkdrc | 2 +- 13 files changed, 185 insertions(+), 165 deletions(-) delete mode 100755 bin/cheat delete mode 100755 bin/cproton.sh delete mode 100755 bin/cycle_sinks.sh delete mode 100755 bin/sup delete mode 100755 bin/sxhkd-help create mode 100644 modules/cli/bin/cheat.nix create mode 100644 modules/cli/bin/cycleSinks.nix create mode 100644 modules/cli/bin/default.nix create mode 100644 modules/cli/bin/protonge.nix create mode 100644 modules/cli/bin/sxhkdHelp.nix diff --git a/bin/cheat b/bin/cheat deleted file mode 100755 index 3f72475..0000000 --- a/bin/cheat +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env zsh -curl -s "cheat.sh/$1" | bat diff --git a/bin/cproton.sh b/bin/cproton.sh deleted file mode 100755 index c8fdb91..0000000 --- a/bin/cproton.sh +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env bash -baseuri="https://github.com/GloriousEggroll/proton-ge-custom/releases/download" -latesturi="https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases/latest" -parameter="${1}" -installComplete=false; -dstpath="$HOME/.steam/root/compatibilitytools.d" #### Destinationforlder of the Proton installations -restartSteam=2 -autoInstall=false -#### Set restartSteam=0 to not restart steam after installing Proton (Keep process untouched) -#### Set restartSteam=1 to autorestart steam after installing Proton -#### Set restartSteam=2 to to get a y/n prompt asking if you want to restart Steam after each installation. - -#### Set autoInstall=true to skip the installation prompt and install the latest not-installed, or any forced Proton GE builds -#### Set autoInstall=false to display a installation-confirmation prompt when installing a Proton GE build - -# ########################################## CProton - Custom Proton Installscript 0.2.2 ########################################## -# Disclaimer: Subversions like the MCC versions of Proton 4.21-GE-1, will install as it's main version and not install separately. -# For now, this may result in false "not installed"-detections or errors while force installing a specific subversion. - -PrintReleases() { - echo "----------Description----------" - echo "" - echo "Run './cproton.sh [VersionName]'" - echo "to download specific versions." - echo "" - echo "------------Releases------------" - curl -s https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases | grep -H "tag_name" | cut -d \" -f4 - echo "--------------------------------" -} - -InstallProtonGE() { - rsp="$(curl -sI "$url" | head -1)" - echo "$rsp" | grep -q 302 || { - echo "$rsp" - exit 1 - } - - [ -d "$dstpath" ] || { - mkdir "$dstpath" - echo [Info] Created "$dstpath" - } - curl -sL "$url" > $dstpath/Proton-"$version".tar.gz # Download archive first - if [ ! -z "$sha512url" ]; then # If there is no sha512 the sha512url is empty - if [ $(sha512sum $dstpath/Proton-"$version".tar.gz | cut -b -128) == $((curl -sL $sha512url)| cut -b -128) ]; then # Only the first 128 bytes are significant - tar xfzv $dstpath/Proton-"$version".tar.gz -C "$dstpath" - installComplete=true - else - echo "sha512sum did not match! Stopping installation." - installComplete=false - fi - else - tar xfzv $dstpath/Proton-"$version".tar.gz -C "$dstpath" - installComplete=true - fi - rm $dstpath/Proton-"$version".tar.gz -} - -RestartSteam() { - if [ "$( pgrep steam )" != "" ]; then - echo "Restarting Steam" - pkill -TERM steam #restarting Steam - sleep 5s - nohup steam /dev/null & - fi -} - -RestartSteamCheck() { - if [ "$( pgrep steam )" != "" ] && [ "$installComplete" = true ]; then - if [ $restartSteam == 2 ]; then - read -r -p "Do you want to restart Steam? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - RestartSteam - else - exit 2 - fi - elif [ $restartSteam == 0 ]; then - exit 0 - fi - RestartSteam - fi -} - -InstallationPrompt() { - if [ "$autoInstall" = true ]; then - if [ ! -d "$dstpath"/Proton-"$version" ]; then - InstallProtonGE - fi - else - read -r -p "Do you want to try to download and (re)install this release? " prompt - if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then - InstallProtonGE - else - echo "Operation canceled" - exit 0 - fi - fi -} - -if [ -z "$parameter" ]; then - version="$(curl -s $latesturi | grep -E -m1 "tag_name" | cut -d \" -f4)" - url=$(curl -s $latesturi | grep -E -m1 "browser_download_url.*.tar.gz" | cut -d \" -f4) - sha512url=$(curl -s $latesturi | grep -E -m1 "browser_download_url.*.sha512sum" | cut -d \" -f4) - if [ -d "$dstpath"/Proton-"$version" ]; then - echo "Proton $version is the latest version and is already installed." - else - echo "Proton $version is the latest version and is not installed yet." - fi -elif [ "$parameter" == "-l" ]; then - PrintReleases -else - url=$baseuri/"$parameter"/Proton-"$parameter".tar.gz - if [ -d "$dstpath"/Proton-"$parameter" ]; then - echo "Proton $parameter is already installed." - else - echo "Proton $parameter is not installed yet." - fi -fi - -if [ ! "$parameter" == "-l" ]; then - InstallationPrompt - RestartSteamCheck -fi diff --git a/bin/cycle_sinks.sh b/bin/cycle_sinks.sh deleted file mode 100755 index 46469e2..0000000 --- a/bin/cycle_sinks.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env nix-shell -#! nix-shell -p pulseaudio -i bash - -# get the default sink -default_sink="$(pactl info | grep -e "Default Sink:" | awk '{print $3}')" -echo "current default: $default_sink" - -# get the sinks -sinks="$(pactl list sinks short | awk '{print $2}')" - -# filter out the default sink -not_active="$(echo "$sinks" | grep -v -e "$default_sink")" - -# get the sink after the dafault one -next_sink="$(echo -e "$sinks\n$not_active" | grep -e "$default_sink" -A 1 | tail -n 1 )" - -# set the new default-sink -pactl set-default-sink "$next_sink" -echo "new default: $next_sink" diff --git a/bin/sup b/bin/sup deleted file mode 100755 index 462ca30..0000000 --- a/bin/sup +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -pushd ~/.dotfiles -if [[ $1 =~ (update) ]]; then - sudo nixos-rebuild switch --flake .# --recreate-lock-file -fi -if [[ $1 =~ (apply) ]]; then - sudo nixos-rebuild switch --flake .# -fi -popd diff --git a/bin/sxhkd-help b/bin/sxhkd-help deleted file mode 100755 index 74926db..0000000 --- a/bin/sxhkd-help +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -awk '/^[a-z]/ && last {print "",$0,"\t",last,""} {last=""} /^#/{last=$0}' ~/.config/sxhkd/sxhkdrc | - column -t -s $'\t' | - rofi -dmenu -i -markup-rows -no-show-icons -width 1000 -lines 15 -yoffset 40 diff --git a/modules/cli/bin/cheat.nix b/modules/cli/bin/cheat.nix new file mode 100644 index 0000000..d5f2ea0 --- /dev/null +++ b/modules/cli/bin/cheat.nix @@ -0,0 +1,9 @@ +{ pkgs }: + +pkgs.writeShellApplication { + name = "cheat"; + + runtimeInputs = with pkgs; [ curl bat ]; + + text = ''curl -s "cheat.sh/$1" | bat''; +} diff --git a/modules/cli/bin/cycleSinks.nix b/modules/cli/bin/cycleSinks.nix new file mode 100644 index 0000000..401caac --- /dev/null +++ b/modules/cli/bin/cycleSinks.nix @@ -0,0 +1,25 @@ +{ pkgs }: + +pkgs.writeShellApplication { + name = "cycle_sinks"; + + runtimeInputs = with pkgs; [ pulseaudio ]; + text = '' + # get the default sink + default_sink="$(pactl info | grep -e "Default Sink:" | awk '{print $3}')" + echo "current default: $default_sink" + + # get the sinks + sinks="$(pactl list sinks short | awk '{print $2}')" + + # filter out the default sink + not_active="$(echo "$sinks" | grep -v -e "$default_sink")" + + # get the sink after the dafault one + next_sink="$(echo -e "$sinks\n$not_active" | grep -e "$default_sink" -A 1 | tail -n 1 )" + + # set the new default-sink + pactl set-default-sink "$next_sink" + echo "new default: $next_sink" + ''; +} diff --git a/modules/cli/bin/default.nix b/modules/cli/bin/default.nix new file mode 100644 index 0000000..0201b50 --- /dev/null +++ b/modules/cli/bin/default.nix @@ -0,0 +1,11 @@ +{ config, lib, pkgs, ... }: + +let + cheat = import ./cheat.nix { inherit pkgs; }; + cycleSinks = import ./cycleSinks.nix { inherit pkgs; }; + protonge = import ./protonge.nix { inherit pkgs; }; + sxhkdHelp = import ./sxhkdHelp.nix { inherit pkgs; }; +in { + home-manager.users.moritz.home.packages = + [ cycleSinks cheat sxhkdHelp protonge ]; +} diff --git a/modules/cli/bin/protonge.nix b/modules/cli/bin/protonge.nix new file mode 100644 index 0000000..f15076b --- /dev/null +++ b/modules/cli/bin/protonge.nix @@ -0,0 +1,127 @@ +{ pkgs }: + +pkgs.writeShellApplication { + name = "protonge"; + runtimeInputs = with pkgs; [ curl ]; + text = '' + baseuri="https://github.com/GloriousEggroll/proton-ge-custom/releases/download" + latesturi="https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases/latest" + installComplete=false; + dstpath="$HOME/.steam/root/compatibilitytools.d" #### Destinationforlder of the Proton installations + restartSteam=2 + autoInstall=false + #### Set restartSteam=0 to not restart steam after installing Proton (Keep process untouched) + #### Set restartSteam=1 to autorestart steam after installing Proton + #### Set restartSteam=2 to to get a y/n prompt asking if you want to restart Steam after each installation. + + #### Set autoInstall=true to skip the installation prompt and install the latest not-installed, or any forced Proton GE builds + #### Set autoInstall=false to display a installation-confirmation prompt when installing a Proton GE build + + # ########################################## CProton - Custom Proton Installscript 0.2.2 ########################################## + # Disclaimer: Subversions like the MCC versions of Proton 4.21-GE-1, will install as it's main version and not install separately. + # For now, this may result in false "not installed"-detections or errors while force installing a specific subversion. + + PrintReleases() { + echo "----------Description----------" + echo "" + echo "Run './cproton.sh [VersionName]'" + echo "to download specific versions." + echo "" + echo "------------Releases------------" + curl -s https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases | grep -H "tag_name" | cut -d \" -f4 + echo "--------------------------------" + } + + InstallProtonGE() { + rsp="$(curl -sI "$url" | head -1)" + echo "$rsp" | grep -q 302 || { + echo "$rsp" + exit 1 + } + + [ -d "$dstpath" ] || { + mkdir "$dstpath" + echo [Info] Created "$dstpath" + } + curl -sL "$url" > "$dstpath/Proton-$version.tar.gz" # Download archive first + if [ -n "$sha512url" ]; then # If there is no sha512 the sha512url is empty + if [ "$(sha512sum "$dstpath/Proton-$version.tar.gz" | cut -b -128)" == "$(curl -sL "$sha512url"| cut -b -128)" ]; then # Only the first 128 bytes are significant + tar xfzv "$dstpath/Proton-$version.tar.gz" -C "$dstpath" + installComplete=true + else + echo "sha512sum did not match! Stopping installation." + installComplete=false + fi + else + tar xfzv "$dstpath/Proton-$version.tar.gz" -C "$dstpath" + installComplete=true + fi + rm "$dstpath/Proton-$version.tar.gz" + } + + RestartSteam() { + if [ "$( pgrep steam )" != "" ]; then + echo "Restarting Steam" + pkill -TERM steam #restarting Steam + sleep 5s + nohup steam /dev/null & + fi + } + + RestartSteamCheck() { + if [ "$( pgrep steam )" != "" ] && [ "$installComplete" = true ]; then + if [ $restartSteam == 2 ]; then + read -r -p "Do you want to restart Steam? " prompt + if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then + RestartSteam + else + exit 2 + fi + elif [ $restartSteam == 0 ]; then + exit 0 + fi + RestartSteam + fi + } + + InstallationPrompt() { + if [ "$autoInstall" = true ]; then + if [ ! -d "$dstpath"/Proton-"$version" ]; then + InstallProtonGE + fi + else + read -r -p "Do you want to try to download and (re)install this release? " prompt + if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then + InstallProtonGE + else + echo "Operation canceled" + exit 0 + fi + fi + } + + if [[ $# -eq 0 ]]; then + version="$(curl -s $latesturi | grep -E -m1 "tag_name" | cut -d \" -f4)" + url=$(curl -s $latesturi | grep -E -m1 "browser_download_url.*.tar.gz" | cut -d \" -f4) + sha512url=$(curl -s $latesturi | grep -E -m1 "browser_download_url.*.sha512sum" | cut -d \" -f4) + if [ -d "$dstpath"/Proton-"$version" ]; then + echo "Proton $version is the latest version and is already installed." + else + echo "Proton $version is the latest version and is not installed yet." + fi + InstallationPrompt + RestartSteamCheck + elif [ "''${1}" == "-l" ]; then + PrintReleases + else + url=$baseuri/"''${1}"/Proton-"''${1}".tar.gz + if [ -d "$dstpath"/Proton-"''${1}" ]; then + echo "Proton ''${1} is already installed." + else + echo "Proton ''${1} is not installed yet." + fi + InstallationPrompt + RestartSteamCheck + fi + ''; +} diff --git a/modules/cli/bin/sxhkdHelp.nix b/modules/cli/bin/sxhkdHelp.nix new file mode 100644 index 0000000..3d476d7 --- /dev/null +++ b/modules/cli/bin/sxhkdHelp.nix @@ -0,0 +1,11 @@ +{ pkgs }: + +pkgs.writeShellApplication { + name = "sxhkd-help"; + runtimeInputs = with pkgs; [ rofi ]; + text = '' + awk '/^[a-z]/ && last {print "",$0,"\t",last,""} {last=""} /^#/{last=$0}' ~/.config/sxhkd/sxhkdrc | + column -t -s $'\t' | + rofi -dmenu -i -markup-rows -no-show-icons -width 1000 -lines 15 -yoffset 40 + ''; +} diff --git a/modules/cli/default.nix b/modules/cli/default.nix index edec697..eb6f25c 100644 --- a/modules/cli/default.nix +++ b/modules/cli/default.nix @@ -1,7 +1,7 @@ { config, lib, pkgs, ... }: { - imports = [ ./adb.nix ./direnv.nix ./git.nix ./nix.nix ./zsh.nix ]; + imports = [ ./bin ./adb.nix ./direnv.nix ./git.nix ./nix.nix ./zsh.nix ]; home-manager.users.moritz = { home.packages = with pkgs; [ # archives diff --git a/modules/default.nix b/modules/default.nix index 8e19688..c4a28a7 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -32,12 +32,6 @@ home.username = "moritz"; home.homeDirectory = "/home/moritz"; - home.sessionPath = [ "/home/moritz/bin" ]; - home.file."bin" = { - recursive = true; - source = ../bin; - }; - xdg.userDirs = { enable = true; createDirectories = true; diff --git a/modules/desktop/bspwm/sxhkdrc b/modules/desktop/bspwm/sxhkdrc index 7fc4865..962a2f1 100755 --- a/modules/desktop/bspwm/sxhkdrc +++ b/modules/desktop/bspwm/sxhkdrc @@ -94,7 +94,7 @@ super + c # Show help super + h - ~/bin/sxhkd-help + sxhkd-help # Apps # start firefox