diff options
34 files changed, 337 insertions, 574 deletions
diff --git a/modules/by-name/lf/lf/commands/base.sh b/modules/by-name/lf/lf/commands/base.sh new file mode 100755 index 00000000..1203bc13 --- /dev/null +++ b/modules/by-name/lf/lf/commands/base.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env sh + +# shellcheck disable=SC2269 +id="$id" + +# Prompt the user for input. +# This will just _print_ the prompt, you still need to `read -r` the user's answer. +# +# # Type +# prompt :: String +# +# # Arguments +# $1 +# : The prompt to print for the user. +prompt() { + printf "=> %s" "$1" +} + +# Run a lf command on the current lf client +# All arguments will run in like they were typed directly into lf. +# # TODO(@bpeetz): Escape the single quotes in the input arguments. <2025-02-02> +# +# # Type +# lf_cmd :: [String] +# +# # Arguments +# $1..$@ +# : The arguments composing the command to run. +lf_cmd() { + arguments="" + for arg in "$@"; do + if [ -z "$arguments" ]; then + arguments="'$arg'" + else + arguments="$arguments '$arg'" + fi + done + + lf -remote "send $id $arguments" +} + +# Print an error message and exit with error code 1. +# The error message will be printed to lf. +# +# # Type +# die :: String +# +# # Arguments +# $1 +# : The error message +die() { + lf_cmd echo "Error: $1" + exit 1 +} + +# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/default.nix b/modules/by-name/lf/lf/commands/default.nix index b3c9acab..f042a7a8 100644 --- a/modules/by-name/lf/lf/commands/default.nix +++ b/modules/by-name/lf/lf/commands/default.nix @@ -1,231 +1,157 @@ -{ - pkgs, - sysLib, - shell_library, - system, - ... -}: let +{pkgs, ...}: let functionCall = { name, dependencies, - replacementStrings, ... }: - sysLib.writeShellScript { + pkgs.writeShellApplication { inherit name; - src = ./scripts/${name}.sh; - keepPath = true; - dependencies = dependencies ++ (builtins.attrValues {inherit (pkgs) dash coreutils;}); - inherit replacementStrings; + text = builtins.readFile ./base.sh + builtins.readFile ./scripts/${name}.sh; + runtimeInputs = dependencies; } + "/bin/${name}"; + # closes the lf tui shell = { name, dependencies, - replacementStrings ? null, ... }: '' ''${{ - ${functionCall {inherit name dependencies replacementStrings;}} + ${functionCall {inherit name dependencies;}} }} - ''; # closes the lf tui + ''; + # runs the command in the ui/term bar pipe = { name, dependencies, - replacementStrings ? null, ... }: '' %{{ - ${functionCall {inherit name dependencies replacementStrings;}} + ${functionCall {inherit name dependencies;}} }} - ''; # runs the command in the ui/term bar + ''; + # runs the command in the background async = { name, dependencies, - replacementStrings ? null, ... }: '' &{{ - ${functionCall {inherit name dependencies replacementStrings;}} + ${functionCall {inherit name dependencies;}} }} - ''; # runs the command in the background + ''; + # adds a prompt after the command has run wait = { name, dependencies, - replacementStrings ? null, ... }: '' !{{ - ${functionCall {inherit name dependencies replacementStrings;}} + ${functionCall {inherit name dependencies;}} }} - ''; # adds a prompt after the command has run + ''; in { - archive = shell { - name = "archive"; - dependencies = builtins.attrValues { - inherit - (pkgs) - fzf - gnutar - xz - p7zip - zip - ; - }; - }; - broot_jump = shell { - name = "broot_jump"; - dependencies = builtins.attrValues { - inherit (pkgs) broot; - }; + archive_compress = shell { + name = "archive_compress"; + dependencies = with pkgs; [ + fzf + gnutar + xz + p7zip + zip + ]; + }; + archive_decompress = pipe { + name = "archive_decompress"; + dependencies = with pkgs; [ + gnutar + unzip + p7zip + ]; }; + + cd_project_root = async { + name = "cd_project_root"; + dependencies = [pkgs.git]; + }; + chmod = pipe { name = "chmod"; dependencies = []; }; - clear_trash = shell { - name = "clear_trash"; - dependencies = builtins.attrValues { - inherit - (pkgs) - fzf - trashy - ; - }; - }; - dl_file = pipe { - name = "dl_file"; - dependencies = builtins.attrValues { - inherit - (pkgs) - xdragon - curl - ; - }; - }; + dragon = pipe { name = "dragon"; - dependencies = builtins.attrValues { - inherit - (pkgs) - xdragon - ; - }; + dependencies = [pkgs.xdragon]; }; dragon_individual = pipe { name = "dragon_individual"; - dependencies = builtins.attrValues { - inherit - (pkgs) - xdragon - ; - }; + dependencies = [pkgs.xdragon]; }; dragon_stay = pipe { name = "dragon_stay"; - dependencies = builtins.attrValues { - inherit - (pkgs) - xdragon - ; - }; + dependencies = [pkgs.xdragon]; }; + execute = shell { name = "execute"; dependencies = []; }; follow_link = pipe { name = "follow_link"; - dependencies = with pkgs; [lf]; - }; - fzf_jump = shell { - name = "fzf_jump"; - dependencies = builtins.attrValues { - inherit (pkgs) fzf lf gnused; - }; + dependencies = []; }; - mk_dir = pipe { - name = "mk_dir"; + + mk_directory = pipe { + name = "mk_directory"; dependencies = []; }; mk_file = shell { name = "mk_file"; dependencies = []; }; - mk_file_and_edit = shell { - name = "mk_file_and_edit"; + mk_link = pipe { + name = "mk_link"; dependencies = []; }; - mk_ln = pipe { - name = "mk_ln"; + mk_script = shell { + name = "mk_script"; dependencies = []; }; - mk_scr_default = shell { - name = "mk_scr_default"; - dependencies = builtins.attrValues {}; - replacementStrings = { - SHELL_LIBRARY_TEMPLATE = "${shell_library.rawTemplate."${system}"}"; - }; - }; - mk_scr_temp = shell { - name = "mk_scr_temp"; - dependencies = builtins.attrValues {}; - replacementStrings = { - SHELL_LIBRARY_TEMPLATE = "${shell_library.rawTemplate."${system}"}"; - TO_BE_SHELL_LIBRARY_PATH = "%SHELL_LIBRARY_PATH"; # replacement is not recursive - }; - }; - view_file = async { - name = "view_file"; - dependencies = builtins.attrValues {inherit (pkgs) file;}; - }; - go_project_base_directory = async { - name = "go_project_root"; - dependencies = []; - }; - restore_trash = shell { - name = "restore_trash"; - dependencies = builtins.attrValues { - inherit - (pkgs) - fzf - trashy - ; - }; - }; + set_clipboard_path = async { name = "set_clipboard_path"; dependencies = [pkgs.wl-clipboard]; }; - set_wall_paper = pipe { - name = "set_wall_paper"; - dependencies = []; + set_wallpaper = pipe { + name = "set_wallpaper"; + dependencies = with pkgs; [ + river # for `riverctl` + swaybg + ]; }; + stripspace = pipe { name = "stripspace"; - dependencies = []; + dependencies = [pkgs.gnused]; }; + trash = pipe { name = "trash"; - dependencies = builtins.attrValues { - inherit - (pkgs) - trashy - trash-cli - findutils - ; - }; - }; - unarchive = pipe { - name = "unarchive"; - dependencies = builtins.attrValues { - inherit - (pkgs) - gnutar - unzip - p7zip - ; - }; + dependencies = [pkgs.trash-cli]; + }; + trash_clear = shell { + name = "trash_clear"; + dependencies = with pkgs; [conceal fzf gawk trashy]; + }; + trash_restore = shell { + name = "trash_restore"; + dependencies = with pkgs; [conceal fzf gaw trashy]; + }; + + view_file = async { + name = "view_file"; + dependencies = with pkgs; [file]; }; } diff --git a/modules/by-name/lf/lf/commands/run.sh b/modules/by-name/lf/lf/commands/run.sh new file mode 100755 index 00000000..fba3653d --- /dev/null +++ b/modules/by-name/lf/lf/commands/run.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env sh + +# Run one of the commands for debugging purposes. + +[ "$#" -gt 1 ] || { + echo "Usage: $0 <script_name> <input_files>.." + exit 2 +} + +script_name="./scripts/$1" +shift 1 + +fx="" +for arg in "$@"; do + if [ -z "$fx" ]; then + fx="$arg" + else + fx="$(printf "%s\n%s" "$fx" "$arg")" + fi +done + +export f="$1" + +# shellcheck source=/dev/null +. ./base.sh +# shellcheck source=/dev/null +. "$script_name" + +# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/archive.sh b/modules/by-name/lf/lf/commands/scripts/archive_compress.sh index 25f40534..5f93de7f 100755 --- a/modules/by-name/lf/lf/commands/scripts/archive.sh +++ b/modules/by-name/lf/lf/commands/scripts/archive_compress.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # Option '-f' disables pathname expansion which can be useful when $f, $fs, and # $fx variables contain names with '*' or '?' characters. However, this option @@ -16,8 +13,7 @@ fx="$fx" # shellcheck disable=SC2269 fs="$fs" -archivers="$(tmp echo gzip xz 7z zip)" -archiver="$(awk '{for (i=1; i<=NF; i++) print $i}' "$archivers" | fzf)" +archiver="$(printf "%s\n" gzip xz 7z zip | fzf)" case "$archiver" in "gzip") @@ -46,26 +42,22 @@ while [ -z "$name" ] || [ -e "$name" ]; do if [ "$ans" = "y" ]; then break else - prompt "Archive name: " + prompt "New Archive name: " fi fi done -root="$(if [ "$(pwd)" = "/" ]; then pwd; else echo "$(pwd)/"; fi)" - # fx contains all selected file name separated by a newline -while read -r raw_file; do - file="$(echo "$raw_file" | sed "s|$root||")" +echo "$fx" | while read -r file; do set -- "$@" "$file" -done <"$(tmp echo "$fx")" +done case "$archiver" in "gzip") - tar --create --gzip -file="$name" "$@" + tar --create --gzip --file="$name" "$@" ;; "xz") - tar --create --file="$name" "$@" - xz --compress -9 --extreme --threads=0 "$name" + tar --create "$@" | xz --compress -9 --format=xz --extreme --threads=0 --stdout >"$name" ;; "7z") 7z a "$name" "$@" diff --git a/modules/by-name/lf/lf/commands/scripts/archive_decompress.sh b/modules/by-name/lf/lf/commands/scripts/archive_decompress.sh new file mode 100755 index 00000000..0e99b98e --- /dev/null +++ b/modules/by-name/lf/lf/commands/scripts/archive_decompress.sh @@ -0,0 +1,29 @@ +# shellcheck shell=sh + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +fx="$fx" +# shellcheck disable=SC2269 +fs="$fs" +# shellcheck disable=SC2269 +id="$id" + +set -f + +unarchive() { + case "$1" in + *.tar.bz | *.tar.bz2 | *.tbz | *.tbz2) tar --extract --bzip2 --verbose --file="$1" ;; + *.tar.gz | *.tgz) tar --extract --gzip --verbose --file="$1" ;; + *.tar.xz | *.txz) tar --extract --xz --verbose --file="$1" ;; + *.tar*) tar --extract --verbose --file="$1" ;; + *.zip) unzip "$1" ;; + *.7z) 7z x "$1" ;; + *) die "'$1' is not a supported file for unarchiving." ;; + esac +} + +while read -r file; do + unarchive "$file" +done <"$fx" +# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/broot_jump.sh b/modules/by-name/lf/lf/commands/scripts/broot_jump.sh deleted file mode 100755 index 8f40ba01..00000000 --- a/modules/by-name/lf/lf/commands/scripts/broot_jump.sh +++ /dev/null @@ -1,25 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -tmp=$(mktmp) -res="$(broot --outcmd "$tmp" && sed 's/cd //' "$tmp")" - -if [ -f "$res" ]; then - cmd="select" -elif [ -d "$res" ]; then - cmd="cd" -fi - -lf -remote "send '$id' '$cmd' '$res'" -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/cd_project_root.sh b/modules/by-name/lf/lf/commands/scripts/cd_project_root.sh new file mode 100755 index 00000000..19100947 --- /dev/null +++ b/modules/by-name/lf/lf/commands/scripts/cd_project_root.sh @@ -0,0 +1,19 @@ +# shellcheck shell=sh + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +fx="$fx" +# shellcheck disable=SC2269 +fs="$fs" +# shellcheck disable=SC2269 +id="$id" + +root="$(git rev-parse --show-toplevel)" +if [ "$root" ]; then + lf_cmd cd "$root" || die "Bug: Failed to cd to project root at '$root'" +else + die "Unable to locate base dir" +fi + +# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/chmod.sh b/modules/by-name/lf/lf/commands/scripts/chmod.sh index 9859127b..3dc5f19c 100755 --- a/modules/by-name/lf/lf/commands/scripts/chmod.sh +++ b/modules/by-name/lf/lf/commands/scripts/chmod.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -12,13 +9,12 @@ fs="$fs" # shellcheck disable=SC2269 id="$id" -readp "Mode bits: " bits -# shellcheck disable=SC2269 -bits="$bits" +prompt "Mode bits: " +read -r bits -while read -r file; do +echo "$fx" | while read -r file; do chmod "$bits" "$file" -done <"$(tmp echo "$fx")" +done -lf -remote 'send reload' +lf_cmd reload # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/clear_trash.sh b/modules/by-name/lf/lf/commands/scripts/clear_trash.sh deleted file mode 100755 index 9052bb5f..00000000 --- a/modules/by-name/lf/lf/commands/scripts/clear_trash.sh +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# could also use --force, for instand removal -trash list | fzf --multi | awk '{print $NF}' | xargs trash empty --match=exact -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/dl_file.sh b/modules/by-name/lf/lf/commands/scripts/dl_file.sh deleted file mode 100755 index c7e3d8b2..00000000 --- a/modules/by-name/lf/lf/commands/scripts/dl_file.sh +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -# Provides the ability to download a file by dropping it into a window - -url="$(dragon -t -x)" - -if [ -n "$url" ]; then - prompt "File Name: " - name="" - while [ -z "$name" ] || [ -e "$name" ]; do - read -r name - if [ -e "$name" ]; then - prompt "File already exists, overwrite [y|N]: " - read -r ans - - if [ "$ans" = "y" ]; then - break - else - prompt "File Name: " - fi - fi - done - - # Download the file with curl - if [ -n "$name" ]; then - curl -o "$name" "$url" || die "curl failed" - fi -else - die "URL is null!" -fi -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/dragon.sh b/modules/by-name/lf/lf/commands/scripts/dragon.sh index cf3c3176..f6653ed3 100755 --- a/modules/by-name/lf/lf/commands/scripts/dragon.sh +++ b/modules/by-name/lf/lf/commands/scripts/dragon.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -12,9 +9,9 @@ fs="$fs" # shellcheck disable=SC2269 id="$id" -while read -r file; do +echo "$fx" | while read -r file; do set -- "$@" "$file" -done <"$(tmp echo "$fx")" +done -dragon -a -x "$@" +dragon --all --and-exit "$@" # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/dragon_individual.sh b/modules/by-name/lf/lf/commands/scripts/dragon_individual.sh index 2465cdfa..27e57354 100755 --- a/modules/by-name/lf/lf/commands/scripts/dragon_individual.sh +++ b/modules/by-name/lf/lf/commands/scripts/dragon_individual.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -12,9 +9,9 @@ fs="$fs" # shellcheck disable=SC2269 id="$id" -while read -r file; do +echo "$fx" | while read -r file; do set -- "$@" "$file" -done <"$(tmp echo "$fx")" +done dragon "$@" # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/dragon_stay.sh b/modules/by-name/lf/lf/commands/scripts/dragon_stay.sh index 066b4c75..54d60cb4 100755 --- a/modules/by-name/lf/lf/commands/scripts/dragon_stay.sh +++ b/modules/by-name/lf/lf/commands/scripts/dragon_stay.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -12,9 +9,9 @@ fs="$fs" # shellcheck disable=SC2269 id="$id" -while read -r file; do +echo "$fx" | while read -r file; do set -- "$@" "$file" -done <"$(tmp echo "$fx")" +done -dragon -a "$@" +dragon --all "$@" # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/execute.sh b/modules/by-name/lf/lf/commands/scripts/execute.sh index aa97fd7f..1d5dc87f 100755 --- a/modules/by-name/lf/lf/commands/scripts/execute.sh +++ b/modules/by-name/lf/lf/commands/scripts/execute.sh @@ -1,7 +1,4 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" diff --git a/modules/by-name/lf/lf/commands/scripts/follow_link.sh b/modules/by-name/lf/lf/commands/scripts/follow_link.sh index 80413990..509fc2e0 100755 --- a/modules/by-name/lf/lf/commands/scripts/follow_link.sh +++ b/modules/by-name/lf/lf/commands/scripts/follow_link.sh @@ -1,7 +1,4 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -14,6 +11,12 @@ id="$id" dir="$(realpath "$f")" -lf -remote "send $id cd \"$dir\"" +if [ -f "$dir" ]; then + cmd="select" +elif [ -d "$dir" ]; then + cmd="cd" +fi + +lf_cmd "$cmd" "$dir" # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/fzf_jump.sh b/modules/by-name/lf/lf/commands/scripts/fzf_jump.sh deleted file mode 100755 index ad1633fb..00000000 --- a/modules/by-name/lf/lf/commands/scripts/fzf_jump.sh +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -res="$(fd . --maxdepth 3 | fzf --header='Jump to location')" - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -if [ -f "$res" ]; then - cmd="select" -elif [ -d "$res" ]; then - cmd="cd" -fi - -lf -remote "send $id $cmd \"$res\"" -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/go_project_root.sh b/modules/by-name/lf/lf/commands/scripts/go_project_root.sh deleted file mode 100755 index 5f7746d3..00000000 --- a/modules/by-name/lf/lf/commands/scripts/go_project_root.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -flake_base_dir="$(search_flake_base_dir)" -if [ "$flake_base_dir" ]; then - lf -remote "send $id cd $flake_base_dir" || die "Bug: No base dir ($flake_base_dir)" -else - die "Unable to locate base dir" -fi - -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/mk_dir.sh b/modules/by-name/lf/lf/commands/scripts/mk_directory.sh index 150f7eed..58921ccd 100755 --- a/modules/by-name/lf/lf/commands/scripts/mk_dir.sh +++ b/modules/by-name/lf/lf/commands/scripts/mk_directory.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -23,7 +20,7 @@ while [ -z "$name" ] || [ -e "$name" ]; do if [ "$ans" = "y" ]; then break else - prompt "Directory Name: " + prompt "New Directory Name: " fi fi done diff --git a/modules/by-name/lf/lf/commands/scripts/mk_file.sh b/modules/by-name/lf/lf/commands/scripts/mk_file.sh index 41d5cf1a..5dafe30d 100755 --- a/modules/by-name/lf/lf/commands/scripts/mk_file.sh +++ b/modules/by-name/lf/lf/commands/scripts/mk_file.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -23,7 +20,7 @@ while [ -z "$name" ] || [ -e "$name" ]; do if [ "$ans" = "y" ]; then break else - prompt "File name: " + prompt "New File name: " fi fi done diff --git a/modules/by-name/lf/lf/commands/scripts/mk_file_and_edit.sh b/modules/by-name/lf/lf/commands/scripts/mk_file_and_edit.sh deleted file mode 100755 index 19fc51db..00000000 --- a/modules/by-name/lf/lf/commands/scripts/mk_file_and_edit.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -prompt "File name: " -name="" -while [ -z "$name" ] || [ -e "$name" ]; do - read -r name - if [ -e "$name" ]; then - prompt "File already exists, overwrite [y|N]: " - read -r ans - - if [ "$ans" = "y" ]; then - break - else - prompt "File name: " - fi - fi -done - -touch "$name" -"$EDITOR" "$name" -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/mk_ln.sh b/modules/by-name/lf/lf/commands/scripts/mk_link.sh index 7fab8e22..40b2099d 100755 --- a/modules/by-name/lf/lf/commands/scripts/mk_ln.sh +++ b/modules/by-name/lf/lf/commands/scripts/mk_link.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -14,20 +11,19 @@ id="$id" while IFS= read -r i; do set -- "$@" "$i" -done <"$HOME"/.local/share/lf/files +done <"$HOME/.local/share/lf/files" mode="$1" shift if [ "$#" -eq 0 ]; then - msg "no files to link" + lf_cmd echo "No files to link." exit 0 fi case "$mode" in copy) - while [ "$#" -gt 0 ]; do - file="$1" + for file in "$@"; do ans="$(basename "$file")" while [ -e "$ans" ]; do @@ -36,10 +32,10 @@ copy) done ln --symbolic --relative "$file" "$(pwd)/$ans" - shift done ;; esac -rm ~/.local/share/lf/files +rm "$HOME/.local/share/lf/files" # lf -remote "send clear" + # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/mk_scr_temp.sh b/modules/by-name/lf/lf/commands/scripts/mk_scr_temp.sh deleted file mode 100755 index 512b5d0b..00000000 --- a/modules/by-name/lf/lf/commands/scripts/mk_scr_temp.sh +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -prompt "Script name: " -name="" -while [ -z "$name" ] || [ -e "$name" ]; do - read -r name - if [ -e "$name" ]; then - prompt "Script already exists, overwrite [y|N]: " - read -r ans - - if [ "$ans" = "y" ]; then - break - else - prompt "Script Name: " - fi - fi -done - -script="$(pwd)"/"$name" - -sed 's|%TO_BE_SHELL_LIBRARY_PATH|%SHELL_LIBRARY_PATH|' "%SHELL_LIBRARY_TEMPLATE" >"$script" -sed -i 's|dash|sh|' "$script" -chmod +x "$script" -"$VISUAL" "$script" - -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/mk_scr_default.sh b/modules/by-name/lf/lf/commands/scripts/mk_script.sh index 47d05080..bbdf6d39 100755 --- a/modules/by-name/lf/lf/commands/scripts/mk_scr_default.sh +++ b/modules/by-name/lf/lf/commands/scripts/mk_script.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -15,8 +12,7 @@ id="$id" prompt "Script name: " name="" while [ -z "$name" ] || [ -e "$name" ]; do - read -r name_base - name="$name_base.sh" + read -r name if [ -e "$name" ]; then prompt "Script already exists, overwrite [y|N]: " read -r ans @@ -24,14 +20,21 @@ while [ -z "$name" ] || [ -e "$name" ]; do if [ "$ans" = "y" ]; then break else - prompt "Script Name: " + prompt "New Script Name: " fi fi done -script="$(pwd)"/"$name" +script="$(pwd)/$name" + +cat <<SCRIPT >"$script" +#! /usr/bin/env sh + + + +# vim: ft=sh +SCRIPT -cat "%SHELL_LIBRARY_TEMPLATE" >"$script" chmod +x "$script" "$VISUAL" "$script" diff --git a/modules/by-name/lf/lf/commands/scripts/restore_trash.sh b/modules/by-name/lf/lf/commands/scripts/restore_trash.sh deleted file mode 100755 index b4ef492f..00000000 --- a/modules/by-name/lf/lf/commands/scripts/restore_trash.sh +++ /dev/null @@ -1,16 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -trash list | fzf --multi | awk '{print $NF}' | xargs trash restore --match=exact -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/set_clipboard_path.sh b/modules/by-name/lf/lf/commands/scripts/set_clipboard_path.sh index ff5f3c01..893452e1 100755 --- a/modules/by-name/lf/lf/commands/scripts/set_clipboard_path.sh +++ b/modules/by-name/lf/lf/commands/scripts/set_clipboard_path.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -17,10 +14,10 @@ if [ -n "$fx" ]; then elif [ -n "$f" ]; then echo "$f" | wl-copy --trim-newline else - lf -remote "send $id echo 'No file selected.'" + lf_cmd echo "No file selected." exit 1 fi -lf -remote "send $id echo 'Path copied'" +lf_cmd echo "Path copied to clipboard." # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/set_wall_paper.sh b/modules/by-name/lf/lf/commands/scripts/set_wall_paper.sh deleted file mode 100755 index 2e607d33..00000000 --- a/modules/by-name/lf/lf/commands/scripts/set_wall_paper.sh +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -die "No yet implemented" # TODO: do what the 'die' says -#sed -i "s,export AWMWALLPAPER='.*',export AWMWALLPAPER='${f}'," ${ZDOTDIR}/.zshenv -#nohub swaybg -i "$f" -#feh --bg-max --no-fehbg "$f" -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/set_wallpaper.sh b/modules/by-name/lf/lf/commands/scripts/set_wallpaper.sh new file mode 100755 index 00000000..4387cd9a --- /dev/null +++ b/modules/by-name/lf/lf/commands/scripts/set_wallpaper.sh @@ -0,0 +1,19 @@ +# shellcheck shell=sh + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +fx="$fx" +# shellcheck disable=SC2269 +fs="$fs" +# shellcheck disable=SC2269 +id="$id" + +pid="$(pgrep swaybg)" +[ -n "$pid" ] && kill "$pid" + +# We cannot control the available commands for river. +# Thus we ensure that it can correctly start `swaybg` +swaybg="$(command -v swaybg)" +riverctl spawn "$swaybg --image \"$f\"" && lf_cmd echo "Temporary background image set." +# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/stripspace.sh b/modules/by-name/lf/lf/commands/scripts/stripspace.sh index 33b1cbcf..95f8f742 100755 --- a/modules/by-name/lf/lf/commands/scripts/stripspace.sh +++ b/modules/by-name/lf/lf/commands/scripts/stripspace.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -12,29 +9,14 @@ fs="$fs" # shellcheck disable=SC2269 id="$id" -files=$(mktmp) -echo "$fx" >"$files" - -awk_source=$(mktmp) -cat <<OFT >"$awk_source" -BEGIN {FS=" "} -{for (i=1; i != NF + 1; i++) - if (i == NF) { - parts[i]=tolower(\$i); - } else { - parts[i]=tolower(\$i"_"); - } -} -END {for (i in parts) printf parts[i]} -OFT +echo "$fx" | while read -r file; do + dirty_name=$(basename "$file") + clean_name=$(echo "$dirty_name" | sed 's/[[:blank:]]\+/_/g' | sed 's/\(.*\)/\L\1/') -while read -r file; do - dirty_name=$(mktmp) - basename "$file" >"$dirty_name" - clean_name=$(awk -f "$awk_source" "$dirty_name") + [ -e "$clean_name" ] && die "file '$clean_name' already exists!" + mv "$dirty_name" "$clean_name" || die "Move failed" - [ -e "$clean_name" ] && die "file \"$clean_name\" already exists!" - mv "$(cat "$dirty_name")" "$clean_name" || die "Move failed" - lf -remote 'send reload' -done <"$files" + lf_cmd reload + lf_cmd select "$clean_name" +done # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/trash.sh b/modules/by-name/lf/lf/commands/scripts/trash.sh index f4878c49..d35c23ce 100755 --- a/modules/by-name/lf/lf/commands/scripts/trash.sh +++ b/modules/by-name/lf/lf/commands/scripts/trash.sh @@ -1,7 +1,4 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" @@ -12,26 +9,9 @@ fs="$fs" # shellcheck disable=SC2269 id="$id" -trash_output=$(mktmp) -expected_error_output=$(mktmp) - -while read -r file; do +echo "$fx" | while read -r file; do set -- "$@" "$file" -done <"$(tmp echo "$fx")" - -# TODO: why are we using trashy at all, when trash-cli can do everything? -# -# try trashy first, through nix because both trashy and trash-cli provide a trash command, which conflicts -nix run nixpkgs#trashy -- put "$@" 2>"$trash_output" - -# FIXME: Find a way, that does not depend on parsing an error message <2023-08-29> -cat <<EOF >"$expected_error_output" -[1;31merror:[0m Error during a \`trash\` operation: Unknown { description: "Path: '\"/.Trash-1000\"'. Message: Permission denied (os error 13)" } -EOF +done -if [ "$(cat "$expected_error_output")" = "$(cat "$trash_output")" ]; then - warning "Deleting with trash-cli to the /.Trash folder" - # this file could not be trashed because it is on the tempfs volume, trash-cli can do this this - trash-put "$@" -fi +trash-put "$@" # vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/trash_clear.sh b/modules/by-name/lf/lf/commands/scripts/trash_clear.sh new file mode 100755 index 00000000..647d1b6e --- /dev/null +++ b/modules/by-name/lf/lf/commands/scripts/trash_clear.sh @@ -0,0 +1,9 @@ +# shellcheck shell=sh + +conceal list | fzf --multi | awk '{for(i=3; i<=NF; i++) {print $i}}' | while read -r file; do + set -- "$@" "$file" +done + +trash empty --match=exact "$@" + +# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/trash_restore.sh b/modules/by-name/lf/lf/commands/scripts/trash_restore.sh new file mode 100755 index 00000000..81aeba01 --- /dev/null +++ b/modules/by-name/lf/lf/commands/scripts/trash_restore.sh @@ -0,0 +1,17 @@ +# shellcheck shell=sh + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +fx="$fx" +# shellcheck disable=SC2269 +fs="$fs" +# shellcheck disable=SC2269 +id="$id" + +conceal list | fzf --multi | awk '{for(i=3; i<=NF; i++) {print $i}}' | while read -r file; do + set -- "$@" "$file" +done + +trash restore --match=exact "$@" +# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/unarchive.sh b/modules/by-name/lf/lf/commands/scripts/unarchive.sh deleted file mode 100755 index d4835f6b..00000000 --- a/modules/by-name/lf/lf/commands/scripts/unarchive.sh +++ /dev/null @@ -1,36 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -fx="$fx" -# shellcheck disable=SC2269 -fs="$fs" -# shellcheck disable=SC2269 -id="$id" - -# extract the current file with the right command -# (xkcd link: https://xkcd.com/1168/) -set -f - -unarchive() { - case "$1" in - *.tar.bz | *.tar.bz2 | *.tbz | *.tbz2) tar xjvf "$1" ;; - *.tar.gz | *.tgz) tar xzvf "$1" ;; - *.tar.xz | *.txz) tar xJvf "$1" ;; - *.zip) unzip "$1" ;; - *.rar) - die "rar is a unfree format!" - ;; - *.7z) 7z x "$1" ;; - *) die "Unsupported format" ;; - esac -} - -while read -r file; do - unarchive "$file" -done <"$fx" -# vim: ft=sh diff --git a/modules/by-name/lf/lf/commands/scripts/view_file.sh b/modules/by-name/lf/lf/commands/scripts/view_file.sh index f75c4868..38e6b778 100755 --- a/modules/by-name/lf/lf/commands/scripts/view_file.sh +++ b/modules/by-name/lf/lf/commands/scripts/view_file.sh @@ -1,7 +1,4 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH +# shellcheck shell=sh # shellcheck disable=SC2269 f="$f" diff --git a/modules/by-name/lf/lf/keybindings/default.nix b/modules/by-name/lf/lf/keybindings/default.nix index f624719f..11da6141 100644 --- a/modules/by-name/lf/lf/keybindings/default.nix +++ b/modules/by-name/lf/lf/keybindings/default.nix @@ -36,21 +36,18 @@ cp = "set_clipboard_path"; # Archive Mappings - au = "unarchive"; - aa = "archive"; + au = "archive_decompress"; + aa = "archive_compress"; # Trash Mappings dd = "trash"; - jc = "clear_trash"; - jr = "restore_trash"; + jc = "trash_clean"; + jr = "trash_restore"; # Dragon Mapping dr = "dragon"; - ds = "dragon-stay"; - di = "dragon-individual"; - #dm = "mvdragon"; - #dc = "cpdragon"; - dl = "dlfile"; + ds = "dragon_stay"; + di = "dragon_individual"; cs = "stripspace"; @@ -68,17 +65,15 @@ y = "copy"; "<enter>" = "open"; - mk = "mk_ln"; + mk = "mk_link"; mf = "mk_file"; - me = "mk_file_and_edit"; - md = "mk_dir"; - ms = "mk_scr_default"; - mt = "mk_scr_temp"; + md = "mk_directory"; + ms = "mk_script"; ch = "chmod"; - bg = "set_wall_paper"; + bg = "set_wallpaper"; r = ":rename; cmd-end"; - H = "go_project_base_directory"; + H = "cd_project_root"; R = "reload"; C = "clear"; U = "unselect"; |