Switch to GNU stow
This commit is contained in:
parent
a2605c4254
commit
d34cecb27e
137 changed files with 39244 additions and 141 deletions
46
scripts/.local/bin/compile
Executable file
46
scripts/.local/bin/compile
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# from https://github.com/LukeSmithxyz/voidrice/blob/master/.local/bin/compiler
|
||||
#
|
||||
# This script will compile or run another finishing operation on a document. I
|
||||
# have this script run via vim.
|
||||
#
|
||||
# Compiles .tex. groff (.mom, .ms), .rmd, .md. Opens .sent files as sent
|
||||
# presentations. Runs scripts based on extention or shebang
|
||||
|
||||
file=$(readlink -f "$1")
|
||||
dir=$(dirname "$file")
|
||||
base="${file%.*}"
|
||||
|
||||
cd "$dir" || exit
|
||||
|
||||
textype() {
|
||||
if (sed 5q "$file" | grep -i -q 'xelatex') && ifinstalled xelatex; then
|
||||
command="xelatex"
|
||||
elif ifinstalled pdflatex; then
|
||||
command="pdflatex"
|
||||
fi
|
||||
$command --output-directory="$dir" "$base" &&
|
||||
grep -i addbibresource "$file" >/dev/null &&
|
||||
biber --input-directory "$dir" "$base" &&
|
||||
$command --output-directory="$dir" "$base" &&
|
||||
$command --output-directory="$dir" "$base"
|
||||
}
|
||||
|
||||
sendtoRmd() {
|
||||
ifinstalled R && echo "require(rmarkdown); render('$1')" | R -q --vanilla
|
||||
}
|
||||
|
||||
case "$file" in
|
||||
*\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf >"$base".pdf ;;
|
||||
*\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf >"$base".pdf ;;
|
||||
*\.[0-9]) refer -PS -e "$file" | groff -mandoc -T pdf >"$base".pdf ;;
|
||||
*\.[Rr]md | *\.md | *\.mkd | *\.markdown) sendtoRmd "$file" ;;
|
||||
*\.tex) textype "$file" ;;
|
||||
*config.h) sudo make install ;;
|
||||
*\.c) cc "$file" -o "$base" && "$base" ;;
|
||||
*\.py) python "$file" ;;
|
||||
*\.go) go run "$file" ;;
|
||||
*\.sent) setsid sent "$file" 2>/dev/null &;;
|
||||
*) sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
|
||||
esac
|
||||
197
scripts/.local/bin/dimswitch
Executable file
197
scripts/.local/bin/dimswitch
Executable file
|
|
@ -0,0 +1,197 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
#==============================================================================
|
||||
# FILE: dimswitch
|
||||
# USAGE: dimswitch [-v] [-h] [-i [application]] [-t theme name] dark/light
|
||||
#
|
||||
# DESCRIPTION:
|
||||
# Toggle alacritty terminal, and between dark
|
||||
# or light mode (if correctly set up in the alacritty.yml file), see REQUIREMENTS
|
||||
# The default action is to toggle between light and dark mode.
|
||||
#
|
||||
# OPTIONS: see function ’usage’ below
|
||||
#
|
||||
# REQUIREMENTS:
|
||||
# The alacritty.yml file needs to have the various color-schemes set up as yaml
|
||||
# anchors. The script itself will then switch the referenced anchor in the actual
|
||||
# `color` key of the file. For an example alacritty.yml refer to its wiki, or
|
||||
# this file: https://gitlab.com/marty-oehme/dotfiles/blob/master/.config/alacritty/alacritty.yml
|
||||
#
|
||||
# NOTES: This script is in active development and its functionality and options
|
||||
# are very much undergoing changes. For now, do not rely on its options
|
||||
# staying stable.
|
||||
#
|
||||
# AUTHOR:
|
||||
# Marty Oehme
|
||||
#
|
||||
# VERSION:
|
||||
ld_version="0.1.1"
|
||||
#==============================================================================
|
||||
|
||||
#=== environment variables ====================================================
|
||||
# DESCRIPTION: Environment variables to configure the script
|
||||
#==============================================================================
|
||||
|
||||
# Sets the programs to be dimmed
|
||||
if [ -z "$DIM_PROGRAMS" ]; then DIM_PROGRAMS=(alacritty); fi
|
||||
|
||||
# Sets the path(s) to the alacritty configuration file
|
||||
if [ -z "$DIM_ALACRITTY_CONF" ]; then DIM_ALACRITTY_CONF="$HOME/.config/alacritty/alacritty.yml:$HOME/.alacritty.yml"; fi
|
||||
|
||||
#=== main function ============================================================
|
||||
# NAME: main
|
||||
# DESCRIPTION: Display usage information for this script.
|
||||
# PARAMETERS: see usage function
|
||||
#==============================================================================
|
||||
main() {
|
||||
local cmd=""
|
||||
local ret=0
|
||||
|
||||
case "$1" in
|
||||
-v | --version)
|
||||
cmd="version"
|
||||
;;
|
||||
-h | --help)
|
||||
cmd="usage"
|
||||
;;
|
||||
-i | --info)
|
||||
cmd="printinfo"
|
||||
;;
|
||||
"")
|
||||
cmd="toggle"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
|
||||
$cmd "$@"
|
||||
ret=$((ret + $?))
|
||||
exit $ret
|
||||
}
|
||||
|
||||
#=== usage function ===========================================================
|
||||
# NAME: usage
|
||||
# DESCRIPTION: Display usage information for this script.
|
||||
#==============================================================================
|
||||
usage() {
|
||||
local name
|
||||
name=$(basename "$0")
|
||||
cat <<EOF
|
||||
$name is a command line tool to toggle alacritty terminal themes.
|
||||
|
||||
Usage:
|
||||
$name # Toggle theme between dark and light mode
|
||||
$name # Set to specified alacritty theme
|
||||
$name -i | --info # Print out programs to be dimmed
|
||||
$name -h | --help # Print this usage information
|
||||
$name -v | --version # Print version information
|
||||
EOF
|
||||
}
|
||||
|
||||
#=== theme info function=======================================================
|
||||
# NAME: printinfo
|
||||
# DESCRIPTION: Displays the programs to be dimmed, and the path to their
|
||||
# configuration files. Currently only alacritty is implemented.
|
||||
#==============================================================================
|
||||
printinfo() {
|
||||
for prog in "${DIM_PROGRAMS[@]}"; do
|
||||
local file
|
||||
file=$(getConfFile "$prog")
|
||||
if [ -z "$file" ]; then
|
||||
file="No associated configuration file found."
|
||||
fi
|
||||
echo "$prog" "-" "$file"
|
||||
done
|
||||
}
|
||||
|
||||
#=== toggle dimming function===================================================
|
||||
# NAME: toggle
|
||||
# DESCRIPTION: Toggles between dark and light mode in alacritty.
|
||||
#==============================================================================
|
||||
toggle() {
|
||||
local file
|
||||
file=$(getConfFile "alacritty")
|
||||
if [ -z "$file" ]; then
|
||||
exit 1
|
||||
fi
|
||||
local line
|
||||
line=$(_findline "$file")
|
||||
if [ -z "$line" ]; then exit 1; fi
|
||||
|
||||
if [[ -n $(_isdark "$file" "$line") ]]; then
|
||||
_replace "$line" "$file" dark light
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -n $(_islight "$file" "$line") ]]; then
|
||||
_replace "$line" "$file" light dark
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Did not find a light/dark theme to toggle in alacritty."
|
||||
exit 1
|
||||
}
|
||||
|
||||
#=== version function==========================================================
|
||||
# NAME: version
|
||||
# DESCRIPTION: Display the current version of the script.
|
||||
#==============================================================================
|
||||
version() {
|
||||
local name
|
||||
name=$(basename "$0")
|
||||
cat <<EOF
|
||||
$name $ld_version
|
||||
EOF
|
||||
}
|
||||
|
||||
#=== get program's config file function =======================================
|
||||
# NAME: getConfFile
|
||||
# DESCRIPTION: Return the configuration file of the selected program.
|
||||
# PARAMETER 1: [String] Name of Program
|
||||
#==============================================================================
|
||||
getConfFile() {
|
||||
local conf
|
||||
case $1 in
|
||||
alacritty)
|
||||
conf=$(_findfile "$DIM_ALACRITTY_CONF")
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "$conf"
|
||||
}
|
||||
|
||||
#=== verify file exists function ==============================================
|
||||
# NAME: _findfile
|
||||
# DESCRIPTION: Splits the string passed in into an array of paths and finds
|
||||
# the first existing file. Return nothing if no file found.
|
||||
# PARAMETER 1: [String] of paths, delimited by ":"
|
||||
#==============================================================================
|
||||
_findfile() {
|
||||
IFS=':' read -ra paths <<<"$1"
|
||||
for i in "${paths[@]}"; do
|
||||
if [ -f "$i" ]; then
|
||||
echo "$i"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# function signature: _findline FILE
|
||||
_findline() {
|
||||
sed -n '/^colors: .*$/=' "$1"
|
||||
}
|
||||
|
||||
# function signature: _islight LINENUMBER FILE
|
||||
_islight() {
|
||||
sed -n "$2p" "$1" | grep -e "-light$"
|
||||
}
|
||||
|
||||
# function signature: _isdark LINENUMBER FILE
|
||||
_isdark() {
|
||||
sed -n "$2p" "$1" | grep -e "-dark$"
|
||||
}
|
||||
|
||||
# function signature: _replace LINENUMBER FILE OLD NEW
|
||||
_replace() {
|
||||
sed -i "$1 s/-$3$/-$4/" "$2"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
15
scripts/.local/bin/dmenuprompt
Executable file
15
scripts/.local/bin/dmenuprompt
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
# A dmenu binary prompt script.
|
||||
# Gives a dmenu prompt labeled with $1 to perform command $2.
|
||||
# For example:
|
||||
# `./prompt "Do you want to shutdown?" "shutdown -h now"`
|
||||
|
||||
if [[ -z $3 ]] || [[ $3 == "normal" ]]; then
|
||||
[ "$(printf "No\\nYes" | dmenu -i -p "$1")" = "Yes" ] && $2
|
||||
elif [[ $3 == "success" ]]; then
|
||||
[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb webgreen -sb greenyellow -sf black -nf white )" = "Yes" ] && $2
|
||||
elif [[ $3 == "warn" ]] || [[ $3 == "warning" ]]; then
|
||||
[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb goldenrod -sb gold -sf black -nf white )" = "Yes" ] && $2
|
||||
elif [[ $3 == "danger" ]]; then
|
||||
[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray )" = "Yes" ] && $2
|
||||
fi
|
||||
4
scripts/.local/bin/ifinstalled
Executable file
4
scripts/.local/bin/ifinstalled
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env sh
|
||||
# If $1 command is not available, error code and notify.
|
||||
|
||||
command -v "$1" >/dev/null || { notify-send "📦 $1" "must be installed for this function." && exit 1 ;}
|
||||
8
scripts/.local/bin/lockscreen
Executable file
8
scripts/.local/bin/lockscreen
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# In case we want to pause any players
|
||||
# (see https://github.com/LukeSmithxyz/voidrice/blob/archi3/.config/sxhkd/sxhkdrc for that)
|
||||
# mpc -q pause
|
||||
# amixer set Master mute
|
||||
|
||||
i3lock -e -f -c 1d2021
|
||||
28
scripts/.local/bin/open-compiled
Executable file
28
scripts/.local/bin/open-compiled
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# opout: "open output": A general handler for opening a file's intended output,
|
||||
# usually the pdf of a compiled document. I find this useful especially
|
||||
# running from vim.
|
||||
#
|
||||
# from https://github.com/LukeSmithxyz/voidrice/tree/master/.local/bin
|
||||
|
||||
basename="$(echo "$1" | sed 's/\.[^\/.]*$//')"
|
||||
|
||||
openCompiledDoc() {
|
||||
if [ -f "$basename".pdf ]; then
|
||||
setsid "$FILEREADER" "$basename.pdf"
|
||||
elif [ -f "$(echo "$basename" | sed 's/ /-/g')".pdf ]; then
|
||||
setsid "$FILEREADER" "$(echo "$basename" | sed 's/ /-/g').pdf"
|
||||
elif [ -f "$(echo "$basename" | sed 's/ /_/g')".pdf ]; then
|
||||
setsid "$FILEREADER" "$(echo "$basename" | sed 's/ /_/g').pdf"
|
||||
elif [ -f "$basename".html ]; then
|
||||
setsid "$BROWSER" "$basename.html"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
# *.tex|*.md|*.rmd|*.ms|*.me|*.mom) setsid "$FILEREADER" "$basename".pdf >/dev/null 2>&1 & ;;
|
||||
*.tex|*.md|*.[Rr]md|*.ms|*.me|*.mom) openCompiledDoc >/dev/null 2>&1 & ;;
|
||||
*.[0-9]) openCompiledDoc >/dev/null 2>&1 & ;;
|
||||
*.html) openCompiledDoc >/dev/null 2>&1 & ;;
|
||||
esac
|
||||
27
scripts/.local/bin/picom_toggle_inactive_opacity
Executable file
27
scripts/.local/bin/picom_toggle_inactive_opacity
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
# toggle the translucency of inactive windows in the picom compositor
|
||||
# by substituting the true/false setting in the picom config file.
|
||||
# picom will automatically reload its settings on any config file changes.
|
||||
#
|
||||
# scipt can be called without arguments to toggle the value;
|
||||
# or with on / off to set it to translucent / opaque, respectively.
|
||||
|
||||
piconf="$XDG_CONFIG_HOME"/picom/picom.conf
|
||||
|
||||
line=$(grep -n "inactive-opacity-override" "$piconf")
|
||||
|
||||
IFS=: read -r line text < <(grep -n "inactive-opacity-override" "$piconf")
|
||||
|
||||
_replace() { # line file old new
|
||||
sed -i "$1 s/$3/$4/" "$2"
|
||||
}
|
||||
|
||||
if [ "$1" = "off" ]; then
|
||||
_replace "$line" "$piconf" "true" "false"
|
||||
elif [ "$1" = "on" ]; then
|
||||
_replace "$line" "$piconf" "false" "true"
|
||||
elif echo "$text" | grep -q "true"; then
|
||||
_replace "$line" "$piconf" "true" "false"
|
||||
elif echo "$text" | grep -q "false"; then
|
||||
_replace "$line" "$piconf" "false" "true"
|
||||
fi
|
||||
18
scripts/.local/bin/polybar-launch
Executable file
18
scripts/.local/bin/polybar-launch
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Terminate already running bar instances
|
||||
killall -q polybar
|
||||
|
||||
# Wait until the processes have been shut down
|
||||
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
|
||||
|
||||
startbars() {
|
||||
for bar in "$@"; do
|
||||
local logfile="/tmp/polybar-$bar.log"
|
||||
printf -- "---\npolybar: %s starting...\n---\n" "$bar" | tee -a "$logfile"
|
||||
polybar "$bar" >>"$logfile" 2>&1 &
|
||||
done
|
||||
}
|
||||
|
||||
startbars "$@"
|
||||
echo "Polybars launched..."
|
||||
48
scripts/.local/bin/rofi/rofi-bang
Executable file
48
scripts/.local/bin/rofi/rofi-bang
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
#
|
||||
# rofi-bang
|
||||
#
|
||||
|
||||
# Allows execution of arbitrary commands through rofi by
|
||||
# invoking shell scripts. These shell scripts can in turn
|
||||
# of course be other rofi commands, which allows the creation
|
||||
# of chained rofi executions (e.g. !c 1+2) to run a
|
||||
# calculator script within rofi and immediately execute it.
|
||||
# Hence, rofi-bang.
|
||||
|
||||
cwd="$XDG_CONFIG_HOME"/rofi
|
||||
if [ ! -d "$cwd" ]; then
|
||||
echo "The necessary directory at $HOME/.config/rofi is not set up correctly."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmdfile="$cwd/rofi-bang-commands.csv"
|
||||
if [ ! -f "$cmdfile" ]; then
|
||||
echo "The nessesary file at $cwd/rofi-bang-commands.csv has not been found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Present the initial selection screen - but as soon as only one candidate is left exit out
|
||||
# since bangs are unique (!text will not be matched by anything else) it should automatically exit
|
||||
# whenever a bang has been typed
|
||||
selection=$(
|
||||
cut <"$cmdfile" -s -d ',' -f 1,2 |
|
||||
sed 's/,/: /' |
|
||||
printf "%s\n%s\n%s" "$(cat -)" "suffix that is not in cmd file" "one last entry" |
|
||||
rofi -dmenu -i -p "Run> " -theme "Arc-Dark" -auto-select |
|
||||
sed 's/: /,/' |
|
||||
head -n 1
|
||||
)
|
||||
# we did not select anything, just exit
|
||||
if [ -z "$selection" ]; then exit 0; fi
|
||||
|
||||
# we selected something, check if it is in the bang commands file
|
||||
# if it is, we should execute the bang
|
||||
is_bang=$(grep "$selection" "$cmdfile")
|
||||
if [ -n "$is_bang" ]; then
|
||||
cmd=$(echo "$is_bang" | cut -s -d ',' -f 4)
|
||||
echo "$cmd" | xargs --no-run-if-empty -I "{}" /bin/bash -c "{}"
|
||||
else
|
||||
echo "not implemented yet, should re-run rofi with the exact same settings"
|
||||
fi
|
||||
240
scripts/.local/bin/rofi/rofi-gopass
Executable file
240
scripts/.local/bin/rofi/rofi-gopass
Executable file
|
|
@ -0,0 +1,240 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Code belongs to https://github.com/carnager/rofi-pass/
|
||||
# Copyright (C) 2019 carnager
|
||||
|
||||
# rofi wrapper. Add custom settings here.
|
||||
_rofi() {
|
||||
rofi -dmenu -no-auto-select -i "$@" -theme /themes/dmenu
|
||||
}
|
||||
|
||||
# default settings
|
||||
backend=xdotool
|
||||
dotool_delay=20
|
||||
daemon_wait=2
|
||||
autotype_delay=2
|
||||
key_autotype="Return"
|
||||
key_usertype="Alt+2"
|
||||
key_passtype="Alt+3"
|
||||
key_actions="Alt+a"
|
||||
key_clipboard="Alt+1"
|
||||
key_fieldtype="Return"
|
||||
|
||||
# read config file
|
||||
get_config_file() {
|
||||
configs=("$ROFI_PASS_CONFIG"
|
||||
"$HOME/.config/rofi-pass/rofi-gopass.conf"
|
||||
"/etc/rofi-gopass.conf")
|
||||
|
||||
# return the first config file with a valid path
|
||||
for config in "${configs[@]}"; do
|
||||
# '! -z' is needed in case ROFI_PASS_CONFIG is not set
|
||||
if [[ ! -z "${config}" && -f "${config}" ]]; then
|
||||
printf "%s" "$config"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Make sure ESC will always end the programm.
|
||||
# Call this function with "exit_check $?" after each rofi call.
|
||||
exit_check() {
|
||||
exit_value=$1
|
||||
if [[ "${exit_value}" == "1" ]]; then
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
clipboard() {
|
||||
local entry
|
||||
local key
|
||||
local value
|
||||
entry="${1}"
|
||||
key="${2}"
|
||||
value="$(gopass show "${entry}" "${key}")"
|
||||
printf '%s' "${value}" | xclip -sel clip
|
||||
notify-send "rofi-gopass" "Copied ${key} to clipboard\nClearing in 45 seconds."
|
||||
(
|
||||
sleep 45
|
||||
printf '%s' "" | xclip
|
||||
printf '%s' "" | xclip -selection clipboard | notify-send "rofi-gopass" "Clipboard cleared"
|
||||
) &
|
||||
exit
|
||||
}
|
||||
|
||||
_ydotoold() {
|
||||
if ! pgrep -x "ydotoold" >/dev/null; then
|
||||
# ydotoold blocks the terminal, so we need to background it.
|
||||
# Sadly this way we never know when the process finished starting up.
|
||||
# Until ydotoold receives proper daemonizing we add a sleep value here.
|
||||
ydotoold &
|
||||
sleep "${daemon_wait}"
|
||||
fi
|
||||
}
|
||||
|
||||
_dotool() {
|
||||
local mode
|
||||
local key
|
||||
mode="${1}"
|
||||
key="${2:-null}"
|
||||
case "${mode}" in
|
||||
"type")
|
||||
case "${backend}" in
|
||||
"xdotool") xdotool type --delay "${dotool_delay}" --file - ;;
|
||||
"ydotool")
|
||||
_ydotoold
|
||||
ydotool type --delay "${dotool_delay}" --file -
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"key")
|
||||
case "${backend}" in
|
||||
"xdotool") xdotool key "${key}" ;;
|
||||
"ydotool")
|
||||
_ydotoold
|
||||
ydotool key "${key}"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
list_passwords() {
|
||||
gopass list --flat
|
||||
}
|
||||
|
||||
autopass() {
|
||||
local entry
|
||||
local autotype
|
||||
entry="${1}"
|
||||
autotype="$(gopass show "${entry}" autotype)"
|
||||
autotype="${autotype:-username :tab pass}"
|
||||
|
||||
for word in ${autotype}; do
|
||||
case "$word" in
|
||||
":tab") _dotool key Tab ;;
|
||||
":space") _dotool key " " ;;
|
||||
":delay") sleep "${autotype_delay}" ;;
|
||||
":enter") _dotool key enter ;;
|
||||
"pass") printf '%s' "$(gopass show --password "${entry}")" | _dotool type ;;
|
||||
*) printf '%s' "$(gopass show "${entry}" "${word}")" | _dotool type ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
list_keys() {
|
||||
# gopass has no option to only list keys, so we need to build the list ourselves.
|
||||
local entry
|
||||
local keys
|
||||
entry="${1}"
|
||||
keys="$(gopass show "${entry}")"
|
||||
printf '%s\n' "${keys}" | while read -r line; do
|
||||
if [[ "${line}" == *": "* ]]; then
|
||||
printf '%s\n' "${line%: *}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
edit_key() {
|
||||
local entry
|
||||
local keys
|
||||
entry="${1}"
|
||||
keys="$(list_keys "${entry}")"
|
||||
key_name=$(printf '%s\n' "${keys}" | _rofi -mesg "Enter new key or chose existing one")
|
||||
exit_check $?
|
||||
value_name=$(printf '%s' "" | _rofi -mesg "Enter Value for key \"${key_name}\"")
|
||||
exit_check $?
|
||||
if [[ -z "${key_name}" ]]; then
|
||||
printf '%s' "${value_name}" | gopass insert -a "${entry}" "${key_name}"
|
||||
else
|
||||
printf '%s' "${value_name}" | gopass insert "${entry}" "${key_name}"
|
||||
fi
|
||||
}
|
||||
|
||||
# For dangerous operations call this function first. You can provide a message as argument.
|
||||
# Example: confirm "Are you sure you want to delete entry?"
|
||||
confirm() {
|
||||
local message
|
||||
message="${1}"
|
||||
confirm_content=(
|
||||
"Yes"
|
||||
"No")
|
||||
|
||||
confirm_menu=$(printf '%s\n' "${confirm_content[@]}" | _rofi -mesg "${message}")
|
||||
exit_check $?
|
||||
case "${confirm_menu}" in
|
||||
"Yes") : ;;
|
||||
"No") exit ;;
|
||||
esac
|
||||
}
|
||||
|
||||
custom_type() {
|
||||
local entry
|
||||
local keys
|
||||
entry="${1}"
|
||||
keys="$(list_keys "${entry}")"
|
||||
key_name=$(printf '%s\n' "${keys}" | _rofi -kb-accept-entry "" -no-custom -kb-custom-1 "${key_clipboard}" -kb-custom-2 "${key_fieldtype}" -mesg "${key_clipboard}: Copy to Clipboard | ${key_fieldtype}: Type Field")
|
||||
local exit_value=$?
|
||||
exit_check "${exit_value}"
|
||||
case "${exit_value}" in
|
||||
"10") clipboard "${entry}" "${key_name}" ;;
|
||||
"11")
|
||||
printf '%s' "$(gopass show "${entry}" "${key_name}")" | _dotool type
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
do_menu() {
|
||||
local entry
|
||||
entry="${1}"
|
||||
action_menu_content=(
|
||||
"< Go Back"
|
||||
"---"
|
||||
"Show Fields"
|
||||
"Add/Edit Keys"
|
||||
"Generate New Password"
|
||||
"Delete Entry"
|
||||
)
|
||||
|
||||
action_menu="$(printf '%s\n' "${action_menu_content[@]}" | _rofi -no-custom -mesg "Selected Entry: ${entry}" -p '> ')"
|
||||
exit_value=$?
|
||||
exit_check "${exit_value}"
|
||||
|
||||
case "${action_menu}" in
|
||||
"< Go Back") main ;;
|
||||
"Show Fields") custom_type "${entry}" ;;
|
||||
"Add/Edit Keys") edit_key "${entry}" ;;
|
||||
"Delete Entry")
|
||||
confirm "Delete ${entry}?"
|
||||
gopass rm -f "${entry}"
|
||||
;;
|
||||
"Generate New Password")
|
||||
confirm "Generate a new password for ${entry}?"
|
||||
gopass generate -f "${entry}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main() {
|
||||
entry="$(list_passwords | _rofi -kb-accept-entry "" -kb-custom-1 "${key_autotype}" -kb-custom-2 "${key_usertype}" -kb-custom-3 "${key_passtype}" -kb-custom-4 "${key_actions}" -mesg "${key_autotype}: Autotype | ${key_usertype}: Type User | ${key_passtype}: Type Pass | ${key_actions}: More Actions")"
|
||||
exit_value=$?
|
||||
exit_check "${exit_value}"
|
||||
case "${exit_value}" in
|
||||
"10")
|
||||
autopass "${entry}"
|
||||
exit
|
||||
;;
|
||||
"11")
|
||||
printf '%s' "$(gopass show "${entry}" username)" | _dotool type
|
||||
exit
|
||||
;;
|
||||
"12")
|
||||
printf '%s' "$(gopass show --password "${entry}")" | _dotool type
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
do_menu "${entry}"
|
||||
}
|
||||
|
||||
main
|
||||
86
scripts/.local/bin/rofi/rofi-surfraw
Executable file
86
scripts/.local/bin/rofi/rofi-surfraw
Executable file
|
|
@ -0,0 +1,86 @@
|
|||
#!/bin/bash
|
||||
|
||||
# source surfraw config
|
||||
source $HOME/.surfraw.conf
|
||||
|
||||
# load global files
|
||||
source /etc/rofi-surfraw.conf
|
||||
|
||||
# create local copy of custom searchengines
|
||||
if [[ ! -d $HOME/.config/rofi-surfraw ]]; then
|
||||
mkdir $HOME/.config/rofi-surfraw/searchengines
|
||||
fi
|
||||
if [[ ! -f $HOME/.config/rofi-surfraw/searchengines ]]; then
|
||||
cp /usr/share/doc/rofi-surfraw/searchengines $HOME/.config/rofi-surfraw/searchengines
|
||||
fi
|
||||
|
||||
# get local config
|
||||
if [[ -f $HOME/.config/rofi-surfraw/config ]]; then
|
||||
source $HOME/.config/rofi-surfraw/config
|
||||
fi
|
||||
|
||||
# get list of search engines from surfraw
|
||||
if [[ $@ == *"--no-list"* ]]; then
|
||||
:
|
||||
else
|
||||
# list=$(sr -elvi | awk '{ print "?"$1 }' | tail -n +2)
|
||||
list=$(sr -elvi | awk '{if (NR!=1) print "?"$1 }')
|
||||
fi
|
||||
|
||||
# get custom engines from text file
|
||||
if [[ $@ == *"--no-custom"* ]]; then
|
||||
:
|
||||
else
|
||||
# custom=$(cat $HOME/.config/rofi-surfraw/searchengines | awk -F ' - ' '{ print $1 }')
|
||||
custom=$(awk -F ' - ' '{ print $1 }' $HOME/.config/rofi-surfraw/searchengines)
|
||||
fi
|
||||
|
||||
main () {
|
||||
# Draw Menu
|
||||
HELP_MSG="<span color=\"$help_color\">Hit Ctrl+Space to complete Engine Name
|
||||
Searches without prepended engine use "${default}"</span>"
|
||||
elvi=$(echo -e "${list}\n${custom}" | rofi -dmenu -mesg "${HELP_MSG}" -p "Search > ")
|
||||
|
||||
# Some logic
|
||||
if [[ $elvi == "" ]]; then exit
|
||||
elif [[ $elvi == "!"* ]]; then
|
||||
entry=$(grep "$(echo "${elvi}" | awk '{ print $1 }')" "$HOME/.config/rofi-surfraw/searchengines")
|
||||
method=$(echo "${entry}" | awk -F ' - ' '{ print $2 }')
|
||||
bang=$(echo "${entry}" | awk -F ' - ' '{ print $3 }')
|
||||
search=$(echo "${elvi}" | awk '{$1=""; print $0}' | cut -c 2-)
|
||||
if [[ $method == "surfraw" ]]; then
|
||||
sr ${bang} ${search}
|
||||
elif [[ $method == "custom" ]]; then
|
||||
"$SURFRAW_graphical_browser" $SURFRAW_graphical_browser_args ${bang}"${search}"
|
||||
fi
|
||||
elif [[ $elvi == "?"* ]]; then
|
||||
name=$(echo "${elvi}" | awk '{ print $1 }' | cut -c 2-)
|
||||
search=$(echo "${elvi}" | awk '{$1=""; print $0}' | cut -c 2-)
|
||||
sr ${name} ${search}
|
||||
else
|
||||
if [[ $default == "!"* ]]; then
|
||||
entry=$(grep "$(echo "${default}" | awk '{ print $1 }')" "$HOME/.config/rofi-surfraw/searchengines")
|
||||
method=$(echo "${entry}" | awk -F ' - ' '{ print $2 }')
|
||||
bang=$(echo "${entry}" | awk -F ' - ' '{ print $3 }')
|
||||
else
|
||||
method="surfraw"
|
||||
bang="$default"
|
||||
fi
|
||||
search="${elvi}"
|
||||
if [[ $method == "surfraw" ]]; then
|
||||
sr ${bang} ${search}
|
||||
elif [[ $method == "custom" ]]; then
|
||||
"$SURFRAW_graphical_browser" $SURFRAW_graphical_browser_args ${bang}"${search}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $1 == "--help" ]]; then
|
||||
echo "rofi-surfraw - (C) 2015 Rasmus Steinke <rasi at xssn dot at>"
|
||||
echo "---"
|
||||
echo "--help this help"
|
||||
echo "--no-list do not show inbuild search engines"
|
||||
echo "--no-custom do not show custom search engines"
|
||||
else
|
||||
main
|
||||
fi
|
||||
1
scripts/.local/bin/syu
Symbolic link
1
scripts/.local/bin/syu
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
/usr/bin/topgrade
|
||||
63
scripts/.local/bin/test/dimswitch.bats
Normal file
63
scripts/.local/bin/test/dimswitch.bats
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
setup() {
|
||||
fut="$BATS_TEST_DIRNAME/../dimswitch"
|
||||
}
|
||||
|
||||
@test "[-v flag] Displays version information" {
|
||||
run $fut -v
|
||||
[ "$status" -eq 0 ]
|
||||
match='^.* [0-9]\.[0-9]\.[0-9]$'
|
||||
echo $output
|
||||
if echo "$output" | grep "$match";then true;else false; fi
|
||||
}
|
||||
|
||||
@test "[--version flag] Displays version information" {
|
||||
run $fut --version
|
||||
[ "$status" -eq 0 ]
|
||||
match='^.* [0-9]\.[0-9]\.[0-9]$'
|
||||
echo $output
|
||||
if echo "$output" | grep "$match";then true;else false; fi
|
||||
}
|
||||
|
||||
@test "[-h flag] Displays usage information" {
|
||||
run $fut -h
|
||||
[ "$status" -eq 0 ]
|
||||
match='^.*Usage:.*$'
|
||||
echo $output
|
||||
if echo "$output" | grep "$match";then true;else false; fi
|
||||
}
|
||||
|
||||
@test "[--help flag] Displays usage information" {
|
||||
run $fut --help
|
||||
[ "$status" -eq 0 ]
|
||||
match='^.*Usage:.*$'
|
||||
echo $output
|
||||
if echo "$output" | grep "$match";then true;else false; fi
|
||||
}
|
||||
|
||||
#### _findfile
|
||||
|
||||
@test "[-i flag] Displays config file for alacritty" {
|
||||
export DIM_PROGRAMS="alacritty"
|
||||
export DIM_ALACRITTY_CONF="$BATS_TEST_DIRNAME/files/alacritty_conf.yml"
|
||||
|
||||
run $fut -i
|
||||
[ "$status" -eq 0 ]
|
||||
match="^alacritty - $DIM_ALACRITTY_CONF"
|
||||
|
||||
echo $output
|
||||
|
||||
if echo "$output" | grep "$match";then true;else false;fi
|
||||
}
|
||||
|
||||
@test "[-i flag] Displays error if no config file found" {
|
||||
export DIM_PROGRAMS="alacritty"
|
||||
export DIM_ALACRITTY_CONF="$BATS_TEST_DIRNAME/files/nonexisting_alacritty_conf.yml"
|
||||
|
||||
run $fut -i
|
||||
[ "$status" -eq 0 ]
|
||||
match="^alacritty - No associated configuration file found."
|
||||
|
||||
echo $output
|
||||
|
||||
if echo "$output" | grep "$match";then true;else false;fi
|
||||
}
|
||||
0
scripts/.local/bin/test/files/alacritty_conf.yml
Normal file
0
scripts/.local/bin/test/files/alacritty_conf.yml
Normal file
39
scripts/.local/bin/test/tm.bats
Normal file
39
scripts/.local/bin/test/tm.bats
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
setup() {
|
||||
fut="$BATS_TEST_DIRNAME/../tm"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf $BATS_TMPDIR/xdg/*
|
||||
}
|
||||
|
||||
@test "runs correctly if invoked without arguments" {
|
||||
run $fut
|
||||
echo "$BATS_TEST_DIRNAME/../tm"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "Errors out if passed a non-existent session file (and some session name)" {
|
||||
run $fut IDONT_EXIST_HERE.session sessionname
|
||||
echo "STATUS: $output"
|
||||
[ "$status" -eq 1 ]
|
||||
echo "OUTPUT: $output"
|
||||
[ "$output" = "can not source session file: 'IDONT_EXIST_HERE.session' does not exist." ]
|
||||
}
|
||||
|
||||
@test "Runs without errors when session file exists in PWD" {
|
||||
touch $PWD/exists.session
|
||||
run $fut exists.session sessionname
|
||||
rm $PWD/exists.session
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "Runs without errors when session file exists in XDG_CONFIG_HOME/tmux/sessions/" {
|
||||
export XDG_CONFIG_HOME=$BATS_TMPDIR
|
||||
mkdir -p $XDG_CONFIG_HOME/tmux/sessions
|
||||
sesdir=$XDG_CONFIG_HOME/tmux/sessions
|
||||
touch $sesdir/exists.session
|
||||
run $fut exists.session sessionname
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
153
scripts/.local/bin/tm
Executable file
153
scripts/.local/bin/tm
Executable file
|
|
@ -0,0 +1,153 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Attach to a tmux session, or create it if it doesnt exist
|
||||
|
||||
if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
|
||||
cat <<-EOF
|
||||
Usage: $0 [FILE] [NAME]
|
||||
Attach to an existing tmux session, or bootstrap a new session.
|
||||
|
||||
If no session exists which fits the criteria, this will create a new one and
|
||||
load it up obeying the commands contained in the FILE argument passed in. It
|
||||
must contain commands which are tmux-command compatible since they will be
|
||||
passed to tmux unmodified. If a session exists and a valid configuration FILE is
|
||||
passed, it will attach itself to the session and execute the session setup inside.
|
||||
|
||||
It will load the default tmux.conf in the following order:
|
||||
- XDG_CONFIG_HOME/tmux/tmux.conf (usually ~/.config/tmux/tmux.conf)
|
||||
- ~/.tmux.conf
|
||||
- /etc/tmux.conf
|
||||
Afterwards, it will apply the contents of the FILE argument passed into the command.
|
||||
|
||||
If no FILE argument is passed it will create an empty session, or attach itself to
|
||||
the session specified.
|
||||
|
||||
If no NAME argument is passed it will automatically create a session name from the
|
||||
FILE argument passed.
|
||||
|
||||
If creating a new session without passing in a FILE argument, and the current directory
|
||||
contains a .tmux.session file, it will automatically use that to set up the session.
|
||||
|
||||
By default, it also looks for valid session files in XDG_CONFIG_HOME/tmux/sessions/
|
||||
This path can be changed by setting the TM_SESSION_PATH environment variable.
|
||||
EOF
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Make tmux obey the XDG specification on startup
|
||||
if [ -e "$XDG_CONFIG_HOME/tmux/tmux.conf" ]; then
|
||||
start="tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf"
|
||||
else
|
||||
start=tmux
|
||||
fi
|
||||
|
||||
_file_exists() {
|
||||
if [ -f "$1" ]; then
|
||||
true
|
||||
else
|
||||
false
|
||||
fi
|
||||
}
|
||||
|
||||
_not_in_tmux() {
|
||||
[ -z "$TMUX" ]
|
||||
}
|
||||
|
||||
_session_exists() {
|
||||
if tmux has-session -t "$session_name" >/dev/null 2>&1; then
|
||||
true
|
||||
else
|
||||
false
|
||||
fi
|
||||
}
|
||||
|
||||
_create_detached_session() {
|
||||
($start new-session -d -s "$session_name")
|
||||
}
|
||||
|
||||
_load_env_session_file() {
|
||||
if [ -f ./.tmux.session ]; then
|
||||
xargs -L1 tmux <./.tmux.session
|
||||
fi
|
||||
}
|
||||
|
||||
_load_session_file() {
|
||||
if [ -f "$session_file" ]; then
|
||||
xargs -L1 tmux <"$session_file"
|
||||
fi
|
||||
}
|
||||
|
||||
_set_session_file_path() {
|
||||
# Prefer local dir if file exists there, fall back to root dir
|
||||
if _file_exists "${1}"; then
|
||||
session_file="${1}"
|
||||
elif _file_exists "${session_dir}${1}"; then
|
||||
session_file="${session_dir}${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
_set_session_vars() {
|
||||
session_dir=${TM_SESSION_DIR:-"$XDG_CONFIG_HOME/tmux/sessions/"}
|
||||
|
||||
# set up session name and config file - if passed in as arguments
|
||||
if [ "$#" -eq 2 ]; then
|
||||
if ! _file_exists "$1" && ! _file_exists "${session_dir}${1}"; then
|
||||
echo >&2 "can not source session file: '${1}' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
_set_session_file_path "$1"
|
||||
session_name=${2}
|
||||
elif [ "$#" -eq 1 ]; then
|
||||
_set_session_file_path "$1"
|
||||
if ! _file_exists "$session_file"; then
|
||||
session_name=${1}
|
||||
fi
|
||||
fi
|
||||
|
||||
# set default session name if none was passed
|
||||
if [ -z "$session_name" ]; then
|
||||
# only if we have a filename should we append it to the session name
|
||||
if [ -n "$session_file" ]; then
|
||||
fname=/$(basename "$session_file" .session)
|
||||
fi
|
||||
# default to parent directory name / config file name for the session
|
||||
session_name=$(basename "$PWD" | sed 's/[^a-zA-Z0-9\-]//g' | tr . -)"$fname"
|
||||
fi
|
||||
}
|
||||
|
||||
_attach_or_create() {
|
||||
# first create a new session if one doesn't exist
|
||||
if ! _session_exists; then
|
||||
_create_detached_session
|
||||
# look for .tmux.session file if no file has been explicitly passed in
|
||||
if ! _file_exists "$session_file"; then
|
||||
_load_env_session_file
|
||||
fi
|
||||
fi
|
||||
|
||||
_load_session_file
|
||||
|
||||
# then attach or switch to the session
|
||||
if _not_in_tmux; then
|
||||
$start attach -t "$session_name"
|
||||
else
|
||||
$start switch-client -t "$session_name"
|
||||
fi
|
||||
|
||||
_unset_functions
|
||||
}
|
||||
|
||||
_unset_functions() {
|
||||
unset _set_session_vars
|
||||
unset _set_session_file_path
|
||||
unset _attach_or_create
|
||||
unset _load_session_file
|
||||
unset _create_detached_session
|
||||
unset _session_exists
|
||||
unset _not_in_tmux
|
||||
unset _file_exists
|
||||
}
|
||||
|
||||
_set_session_vars "$@"
|
||||
_attach_or_create
|
||||
exit 0
|
||||
97
scripts/.local/bin/umpv
Executable file
97
scripts/.local/bin/umpv
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This script emulates "unique application" functionality on Linux. When starting
|
||||
playback with this script, it will try to reuse an already running instance of
|
||||
mpv (but only if that was started with umpv). Other mpv instances (not started
|
||||
by umpv) are ignored, and the script doesn't know about them.
|
||||
|
||||
This only takes filenames as arguments. Custom options can't be used; the script
|
||||
interprets them as filenames. If mpv is already running, the files passed to
|
||||
umpv are appended to mpv's internal playlist. If a file does not exist or is
|
||||
otherwise not playable, mpv will skip the playlist entry when attempting to
|
||||
play it (from the GUI perspective, it's silently ignored).
|
||||
|
||||
If mpv isn't running yet, this script will start mpv and let it control the
|
||||
current terminal. It will not write output to stdout/stderr, because this
|
||||
will typically just fill ~/.xsession-errors with garbage.
|
||||
|
||||
mpv will terminate if there are no more files to play, and running the umpv
|
||||
script after that will start a new mpv instance.
|
||||
|
||||
Note that you can control the mpv instance by writing to the command fifo:
|
||||
|
||||
echo "cycle fullscreen" > ~/.umpv_fifo
|
||||
|
||||
Note: you can supply custom mpv path and options with the MPV environment
|
||||
variable. The environment variable will be split on whitespace, and the
|
||||
first item is used as path to mpv binary and the rest is passed as options
|
||||
_if_ the script starts mpv. If mpv is not started by the script (i.e. mpv
|
||||
is already running), this will be ignored.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import errno
|
||||
import subprocess
|
||||
import fcntl
|
||||
import stat
|
||||
import string
|
||||
|
||||
files = sys.argv[1:]
|
||||
|
||||
# this is the same method mpv uses to decide this
|
||||
def is_url(filename):
|
||||
parts = filename.split("://", 1)
|
||||
if len(parts) < 2:
|
||||
return False
|
||||
# protocol prefix has no special characters => it's an URL
|
||||
allowed_symbols = string.ascii_letters + string.digits + '_'
|
||||
prefix = parts[0]
|
||||
return all(map(lambda c: c in allowed_symbols, prefix))
|
||||
|
||||
# make them absolute; also makes them safe against interpretation as options
|
||||
def make_abs(filename):
|
||||
if not is_url(filename):
|
||||
return os.path.abspath(filename)
|
||||
return filename
|
||||
files = [make_abs(f) for f in files]
|
||||
|
||||
FIFO = os.path.join(os.getenv("HOME"), ".umpv_fifo")
|
||||
|
||||
fifo_fd = -1
|
||||
try:
|
||||
fifo_fd = os.open(FIFO, os.O_NONBLOCK | os.O_WRONLY)
|
||||
except OSError as e:
|
||||
if e.errno == errno.ENXIO:
|
||||
pass # pipe has no writer
|
||||
elif e.errno == errno.ENOENT:
|
||||
pass # doesn't exist
|
||||
else:
|
||||
raise e
|
||||
|
||||
if fifo_fd >= 0:
|
||||
# Unhandled race condition: what if mpv is terminating right now?
|
||||
fcntl.fcntl(fifo_fd, fcntl.F_SETFL, 0) # set blocking mode
|
||||
fifo = os.fdopen(fifo_fd, "w")
|
||||
for f in files:
|
||||
# escape: \ \n "
|
||||
f = f.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n")
|
||||
f = "\"" + f + "\""
|
||||
fifo.write("raw loadfile " + f + " append\n")
|
||||
else:
|
||||
# Recreate pipe if it doesn't already exist.
|
||||
# Also makes sure it's safe, and no other user can create a bogus pipe
|
||||
# that breaks security.
|
||||
try:
|
||||
os.unlink(FIFO)
|
||||
except OSError as e:
|
||||
pass
|
||||
os.mkfifo(FIFO, 0o600)
|
||||
|
||||
opts = (os.getenv("MPV") or "mpv").split()
|
||||
opts.extend(["--no-terminal", "--force-window", "--input-file=" + FIFO,
|
||||
"--"])
|
||||
opts.extend(files)
|
||||
|
||||
subprocess.check_call(opts)
|
||||
12
scripts/.local/bin/vifm/ueberzug
Executable file
12
scripts/.local/bin/vifm/ueberzug
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/python
|
||||
# EASY-INSTALL-ENTRY-SCRIPT: 'ueberzug==18.1.5','console_scripts','ueberzug'
|
||||
__requires__ = 'ueberzug==18.1.5'
|
||||
import re
|
||||
import sys
|
||||
from pkg_resources import load_entry_point
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
|
||||
sys.exit(
|
||||
load_entry_point('ueberzug==18.1.5', 'console_scripts', 'ueberzug')()
|
||||
)
|
||||
154
scripts/.local/bin/vifm/vifmimg
Executable file
154
scripts/.local/bin/vifm/vifmimg
Executable file
|
|
@ -0,0 +1,154 @@
|
|||
#!/usr/bin/env bash
|
||||
readonly ID_PREVIEW="preview"
|
||||
|
||||
#PLAY_GIF="yes"
|
||||
# By enabling this option the GIF will be animated, by leaving it commented like it
|
||||
# is now will make the gif previews behave the same way as video previews.
|
||||
|
||||
#AUTO_REMOVE="yes"
|
||||
# By enabling this option the script will remove the preview file after it is drawn
|
||||
# and by doing so the preview will always be up-to-date with the file.
|
||||
# This however, requires more CPU and therefore affects the overall performance.
|
||||
|
||||
# The messy code below is for moving pages in pdf files in the vifm file preview by
|
||||
# utilizing the < and > keys which will be bound to `vifmimg inc` or `vifmimg dec`.
|
||||
PDF_PAGE_CONFIG="$HOME/.config/vifm/vifmimgpdfpage"
|
||||
PDF_FILE_CONFIG="$HOME/.config/vifm/vifmimgpdffile"
|
||||
PDF_PAGE=1
|
||||
PDF_FILE=""
|
||||
# Initialize the variables and required files
|
||||
[[ -f "$PDF_PAGE_CONFIG" ]] && PDF_PAGE=$(cat $PDF_PAGE_CONFIG) || touch $PDF_PAGE_CONFIG
|
||||
[[ -f "$PDF_FILE_CONFIG" ]] && PDF_FILE=$(cat $PDF_FILE_CONFIG) || touch $PDF_FILE_CONFIG
|
||||
|
||||
|
||||
# Create temporary working directory if the directory structure doesn't exist
|
||||
if [[ ! -d "/tmp$PWD/" ]]; then
|
||||
mkdir -p "/tmp$PWD/"
|
||||
fi
|
||||
|
||||
function inc() {
|
||||
VAL="$(cat $PDF_PAGE_CONFIG)"
|
||||
echo "$(expr $VAL + 1)" > $PDF_PAGE_CONFIG
|
||||
}
|
||||
|
||||
function dec() {
|
||||
VAL="$(cat $PDF_PAGE_CONFIG)"
|
||||
echo "$(expr $VAL - 1)" > $PDF_PAGE_CONFIG
|
||||
if [[ $VAL -le 0 ]]; then
|
||||
echo 0 > $PDF_PAGE_CONFIG
|
||||
fi
|
||||
}
|
||||
|
||||
function previewclear() {
|
||||
declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function fileclean() {
|
||||
if [[ -f "/tmp$PWD/$6.png" ]]; then
|
||||
rm -f "/tmp$PWD/$6.png"
|
||||
elif [[ -d "/tmp$PWD/$6/" ]]; then
|
||||
rm -rf "/tmp$PWD/$6/"
|
||||
fi
|
||||
}
|
||||
|
||||
function preview() {
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="$PWD/$6") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function previewvideo() {
|
||||
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
|
||||
ffmpegthumbnailer -i "$PWD/$6" -o "/tmp$PWD/$6.png" -s 0 -q 10
|
||||
fi
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function previewepub() {
|
||||
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
|
||||
epub-thumbnailer "$6" "/tmp$PWD/$6.png" 1024
|
||||
fi
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
function previewgif() {
|
||||
if [[ ! -d "/tmp$PWD/$6/" ]]; then
|
||||
mkdir -p "/tmp$PWD/$6/"
|
||||
convert -coalesce "$PWD/$6" "/tmp$PWD/$6/$6.png"
|
||||
fi
|
||||
if [[ ! -z "$PLAY_GIF" ]]; then
|
||||
for frame in $(ls -1 /tmp$PWD/$6/$6*.png | sort -V); do
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="$frame") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
# Sleep between frames to make the animation smooth.
|
||||
sleep .07
|
||||
done
|
||||
else
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6/$6-0.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
fi
|
||||
}
|
||||
|
||||
function previewpdf() {
|
||||
if [[ ! "$6" == "$PDF_FILE" ]]; then
|
||||
PDF_PAGE=1
|
||||
echo 1 > $PDF_PAGE_CONFIG
|
||||
rm -f "/tmp$PWD/$6.png"
|
||||
fi
|
||||
|
||||
if [[ ! "$PDF_PAGE" == "1" ]] && [[ -f "/tmp$PWD/$6.png" ]]; then
|
||||
rm -f "/tmp$PWD/$6.png"
|
||||
fi
|
||||
|
||||
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
|
||||
pdftoppm -png -f $PDF_PAGE -singlefile "$6" "/tmp$PWD/$6"
|
||||
fi
|
||||
echo "$6" > $PDF_FILE_CONFIG
|
||||
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
|
||||
function previewmagick() {
|
||||
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
|
||||
convert -thumbnail $(identify -format "%wx%h" "$6") "$PWD/$6" "/tmp$PWD/$6.png"
|
||||
fi
|
||||
declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
|
||||
[x]="$2" [y]="$3" [width]="$4" [height]="$5" \
|
||||
[path]="/tmp$PWD/$6.png") \
|
||||
> "$FIFO_UEBERZUG"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function main() {
|
||||
case "$1" in
|
||||
"inc") inc "$@" ;;
|
||||
"dec") dec "$@" ;;
|
||||
"clear") previewclear "$@" ;;
|
||||
"clean") fileclean "$@" ;;
|
||||
"draw") preview "$@" ;;
|
||||
"videopreview") previewvideo "$@" ;;
|
||||
"epubpreview") previewepub "$@" ;;
|
||||
"gifpreview") previewgif "$@" ;;
|
||||
"pdfpreview") previewpdf "$@" ;;
|
||||
"magickpreview") previewmagick "$@" ;;
|
||||
"*") echo "Unknown command: '$@'" ;;
|
||||
esac
|
||||
}
|
||||
main "$@"
|
||||
15
scripts/.local/bin/vifm/vifmrun
Executable file
15
scripts/.local/bin/vifm/vifmrun
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}"
|
||||
|
||||
function cleanup {
|
||||
rm "$FIFO_UEBERZUG" 2>/dev/null
|
||||
pkill -P $$ 2>/dev/null
|
||||
}
|
||||
pkill -P $$ 2>/dev/null
|
||||
rm "$FIFO_UEBERZUG" 2>/dev/null
|
||||
mkfifo "$FIFO_UEBERZUG" >/dev/null
|
||||
trap cleanup EXIT 2>/dev/null
|
||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash 2>&1 >/dev/null &
|
||||
|
||||
vifm $1
|
||||
cleanup
|
||||
Loading…
Add table
Add a link
Reference in a new issue