1
0
mirror of https://github.com/kmein/niveum synced 2026-03-18 19:11:08 +01:00

feat(packages): package tolino-screensaver, fzf-wrappers, dirmir

This commit is contained in:
Kierán Meinhardt
2019-08-26 16:40:52 +02:00
parent aaf4b54c04
commit 55041ff122
13 changed files with 100 additions and 73 deletions

View File

@@ -1,22 +0,0 @@
#!/bin/sh
SOURCE="$1"
TARGET="$2"
if [ ! -d "$SOURCE" ] || [ $# -ne 2 ]; then
echo >/dev/stderr "Usage: $1 SOURCE TARGET"
exit 1
fi
if [ -e "$TARGET" ]; then
echo >/dev/stderr "$TARGET" already exists. Please use a different name.
exit 1
fi
for entry in $(find "$SOURCE"); do
if [ -d "$entry" ]; then
mkdir -p "$TARGET/$entry"
else
# create a file with the same permissions as $entry
install -m "$(stat -c %a "$entry")" /dev/null "$TARGET/$entry"
fi
done

View File

@@ -1,3 +0,0 @@
#!/usr/bin/env bash
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"

View File

@@ -1,12 +0,0 @@
#!/bin/sh
if [ "$UID" != "0" ]; then
pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
else
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
fi
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi

View File

@@ -1,7 +0,0 @@
#!/usr/bin/env bash
IFS=$'\n' out=("$(fzf-tmux --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)")
key=$(head -1 <<< "$out")
file=$(head -2 <<< "$out" | tail -1)
if [ -n "$file" ]; then
[ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file"
fi

View File

@@ -1,10 +0,0 @@
#!/bin/sh
source_image="$1"
if [ -e "$source_image" ]; then
convert -type Grayscale -resize 758x1024 "$source_image" "suspend.jpg"
else
echo >/dev/stderr "$1 must exist."
exit 1
fi

View File

@@ -1,7 +0,0 @@
#!/usr/bin/env bash
file="$(rg $@ | fzf -0 -1 | awk -F: '{print $1}')"
if [[ -n $file ]]
then
vim $file
fi

27
packages/dirmir.nix Normal file
View File

@@ -0,0 +1,27 @@
{ writers, coreutils, findutils }:
let name = "dirmir";
in writers.writeDashBin name ''
export PATH=$PATH:${coreutils}/bin:${findutils}/bin
SOURCE="$1"
TARGET="$2"
if [ ! -d "$SOURCE" ] || [ $# -ne 2 ]; then
echo >/dev/stderr "Usage: ${name} SOURCE TARGET"
exit 1
fi
if [ -e "$TARGET" ]; then
echo >/dev/stderr "$TARGET" already exists. Please use a different name.
exit 1
fi
for entry in $(find "$SOURCE"); do
if [ -d "$entry" ]; then
mkdir -p "$TARGET/$entry"
else
# create a file with the same permissions as $entry
install -m "$(stat -c %a "$entry")" /dev/null "$TARGET/$entry"
fi
done
''

33
packages/fzf-wrappers.nix Normal file
View File

@@ -0,0 +1,33 @@
{ write, lib, fzf, writers, findutils, procps, gnused, gawk, ripgrep }:
let
wrappers.fe = writers.writeBash "fe" ''
export PATH=$PATH:${fzf}/bin
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
[[ -n "$files" ]] && ''${EDITOR:-vim} "''${files[@]}"
'';
wrappers.fkill = writers.writeDash "fkill" ''
export PATH=$PATH:${procps}/bin:${gawk}/bin:${gnused}/bin:${fzf}/bin:${findutils}/bin
if [ "$UID" != "0" ]; then
pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
else
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
fi
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -''${1:-9}
fi
'';
wrappers.vg = writers.writeBash "vg" ''
export PATH=$PATH:${ripgrep}/bin:${fzf}/bin:${gawk}/bin
file="$(rg "$@" | fzf -0 -1 | awk -F: '{print $1}')"
if [[ -n $file ]]
then
''${EDITOR:-vim} "$file"
fi
'';
in write "fzf-wrappers" (lib.mapAttrs' (name: link: lib.nameValuePair "/bin/${name}" {inherit link;}) wrappers)

View File

@@ -1,6 +1,17 @@
{ writeShellScriptBin, texlive }:
writeShellScriptBin "man-pdf" ''
for program in "$@"; do
man -t "$program" | ${texlive.combined.scheme-basic}/bin/ps2pdf
done
{ writeShellScriptBin, ghostscript, man }:
let
name = "man-pdf";
in writeShellScriptBin name ''
if [ $# -eq 1 ]; then
man_entry="$1"
elif [ $# -eq 2 ]; then
man_page="$1"
man_entry="$2"
else
echo >/dev/stderr "Usage: ${name} [MAN-PAGE] ENTRY"
exit 1
fi
echo "${man}/bin/man "''${man_page:-}" "$man_entry" | ${ghostscript}/bin/ps2pdf - "$man_entry.pdf""
${man}/bin/man "''${man_page:-}" "$man_entry" | ${ghostscript}/bin/ps2pdf - "$man_entry.pdf"
''

View File

@@ -0,0 +1,11 @@
{ writers, imagemagick }:
writers.writeDashBin "tolino-screensaver" ''
source_image="$1"
if [ -e "$source_image" ]; then
${imagemagick}/bin/convert -type Grayscale -resize 758x1024 "$source_image" "suspend.jpg"
else
echo >/dev/stderr "$1 must exist."
exit 1
fi
''