Add old dotfiles
This commit is contained in:
commit
1cace80e48
192 files changed
+13538
No files matched your search
Executable
+196
@@ -0,0 +1,196 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Script name: _dm-helper
|
||||
# Description: A helper script for the other scripts in the collection.
|
||||
# Dependencies:
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: Simon Ingelsson
|
||||
# HostGrady
|
||||
# aryak1
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
echo "This is a helper-script it does not do anything on its own."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
######################
|
||||
# Error handling #
|
||||
######################
|
||||
|
||||
# Simple warn function
|
||||
warn() {
|
||||
printf 'Warn: %s\n' "$1"
|
||||
}
|
||||
|
||||
# Simple error function
|
||||
err() {
|
||||
printf 'Error: %s\n' "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
############################
|
||||
# Dislay server checks #
|
||||
############################
|
||||
|
||||
# Boiler code for if you want to do something with display servers
|
||||
|
||||
#function() {
|
||||
# case "$XDG_SESSION_TYPE" in
|
||||
# 'x11') something with x;;
|
||||
# 'wayland') something with wayland;;
|
||||
# *) err "Unknown display server";;
|
||||
# esac
|
||||
#}
|
||||
|
||||
# Function to copy to clipboard with different tools depending on the display server
|
||||
cp2cb() {
|
||||
case "$XDG_SESSION_TYPE" in
|
||||
'x11') xclip -r -selection clipboard ;;
|
||||
'wayland') wl-copy -n ;;
|
||||
*) err "Unknown display server" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
grep-desktop() {
|
||||
case "$XDG_SESSION_TYPE" in
|
||||
'x11') grep "Name=" /usr/share/xsessions/*.desktop | cut -d'=' -f2 ;;
|
||||
'wayland') grep "Name=" /usr/share/wayland-sessions/*.desktop | cut -d'=' -f2 || grep "Name=" /usr/share/xsessions/*.desktop | grep -i "wayland" | cut -d'=' -f2 | cut -d' ' -f1 ;;
|
||||
*) err "Unknown display server" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
###############
|
||||
# Parsing #
|
||||
###############
|
||||
|
||||
# simple function which provides a key-value pair in the form of the DM_XML_TAG and DM_XML_VALUE varaibles
|
||||
xmlgetnext() {
|
||||
local IFS='>'
|
||||
# we need to mangle backslashes for this to work (SC2162)
|
||||
# The DM_XML_* variables are global variables and are expected to be read and dealt with by someone else (SC2034)
|
||||
# shellcheck disable=SC2162,SC2034
|
||||
read -d '<' DM_XML_TAG DM_XML_VALUE
|
||||
}
|
||||
|
||||
#################
|
||||
# Help Function #
|
||||
#################
|
||||
|
||||
# Every script has a '-h' option that displays the following information.
|
||||
help() {
|
||||
printf '%s%s%s\n' "Usage: $(basename "$0") [options]
|
||||
$(grep '^# Description: ' "$0" | sed 's/# Description: /Description: /g')
|
||||
$(grep '^# Dependencies: ' "$0" | sed 's/# Dependencies: /Dependencies: /g')
|
||||
|
||||
The folowing OPTIONS are accepted:
|
||||
-h displays this help page
|
||||
-d runs the script using 'dmenu'
|
||||
-f runs the script using 'fzf'
|
||||
-r runs the script using 'rofi'
|
||||
|
||||
Running" " $(basename "$0") " "without any argument defaults to using 'dmenu'
|
||||
Run 'man dmscripts' for more information" >/dev/stderr
|
||||
}
|
||||
|
||||
####################
|
||||
# Handle Arguments #
|
||||
####################
|
||||
|
||||
# this function is a simple parser designed to get the menu program and then exit prematurally
|
||||
get_menu_program() {
|
||||
# If script is run with '-d', it will use 'dmenu'
|
||||
# If script is run with '-f', it will use 'fzf'
|
||||
# If script is run with '-r', it will use 'rofi'
|
||||
while getopts "dfrh" arg 2>/dev/null; do
|
||||
case "${arg}" in
|
||||
d) # shellcheck disable=SC2153
|
||||
echo "${DMENU}"
|
||||
return 0
|
||||
;;
|
||||
f) # shellcheck disable=SC2153
|
||||
echo "${FMENU}"
|
||||
return 0
|
||||
;;
|
||||
r) # shellcheck disable=SC2153
|
||||
echo "${RMENU}"
|
||||
return 0
|
||||
;;
|
||||
h)
|
||||
help
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
echo "invalid option:
|
||||
Type $(basename "$0") -h for help" >/dev/stderr
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo "Did not find menu argument, using \${DMENU}" >/dev/stderr
|
||||
# shellcheck disable=SC2153
|
||||
echo "${DMENU}"
|
||||
}
|
||||
|
||||
####################
|
||||
# Boilerplate Code #
|
||||
####################
|
||||
|
||||
# this function will source the dmscripts config files in the order specified below:
|
||||
#
|
||||
# Config priority (in order of which code takes precendent over the other):
|
||||
# 1. Git repository config - For developers
|
||||
# 2. $XDG_CONFIG_HOME/dmscripts/config || $HOME/.config/dmscripts/config - For local edits
|
||||
# 3. /etc/dmscripts/config - For the gloabl/default configuration
|
||||
#
|
||||
# Only 1 file is ever sourced
|
||||
|
||||
# this warning is simply not necessary anywhere in the scope
|
||||
# shellcheck disable=SC1091
|
||||
source_dmscripts_configs() {
|
||||
# this is to ensure this variable is defined
|
||||
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-}"
|
||||
|
||||
[ -f "../config/config" ] && source "../config/config" && return 0
|
||||
[ -z "$XDG_CONFIG_HOME" ] && [ -f "$HOME/.config/dmscripts/config" ] && source "$HOME/.config/dmscripts/config" && return 0
|
||||
[ -n "$XDG_CONFIG_HOME" ] && [ -f "$XDG_CONFIG_HOME/dmscripts/config" ] && source "$XDG_CONFIG_HOME/dmscripts/config" && return 0
|
||||
[ -f "/etc/dmscripts/config" ] && source "/etc/dmscripts/config"
|
||||
}
|
||||
|
||||
# checks the base configuration file and compares it with the local configuration file
|
||||
# if the numbers are different then the code will return 0, else 1
|
||||
#
|
||||
# this does not check the git config as it doesn't make sense
|
||||
configs_are_different() {
|
||||
local _base_file=""
|
||||
local _config_file=""
|
||||
|
||||
# DM_SHUTUP is a variable in the dmscript config that is intended to silence the notifications.
|
||||
DM_SHUTUP="${DM_SHUTUP:-}"
|
||||
|
||||
# it cannot determine if the files are different if it does not exist
|
||||
[ -f "/etc/dmscripts/config" ] && _base_file="/etc/dmscripts/config" || return 1
|
||||
|
||||
# this is essentially the same idea as seen previous just with different variable names
|
||||
local _xdg_config_home="${XDG_CONFIG_HOME:-}"
|
||||
|
||||
[ -z "$_xdg_config_home" ] && [ -f "$HOME/.config/dmscripts/config" ] && _config_file="$HOME/.config/dmscripts/config"
|
||||
[ -n "$_xdg_config_home" ] && [ -f "$XDG_CONFIG_HOME/dmscripts/config" ] && _config_file="$XDG_CONFIG_HOME/dmscripts/config"
|
||||
|
||||
# if there is no other config files then just exit.
|
||||
[ -z "$_config_file" ] && return 1
|
||||
|
||||
_config_file_revision=$(grep "^_revision=" "${_config_file}")
|
||||
_base_file_revision=$(grep "^_revision=" "${_base_file}")
|
||||
|
||||
if [[ ! "${_config_file_revision}" == "${_base_file_revision}" ]]; then
|
||||
if [ -z "$DM_SHUTUP" ]; then
|
||||
notify-send "dmscripts configuration outdated" "Review the differences of /etc/dmscripts/config and your local config and apply changes accordingly (dont forget to bump the revision number)"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
Executable
+96
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-dictionary
|
||||
# Description: Uses the translate package as a dictionary.
|
||||
# Dependencies: dmenu, fzf, rofi, translate-shell, didyoumean
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: Francesco Prem Solidoro
|
||||
# Derek Taylor
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
# dmenu expects some sort of input piped into it.
|
||||
# The echo to /dev/null is just a hacky way of giving
|
||||
# dmenu some input without really giving any input.
|
||||
# shellcheck disable=SC2260
|
||||
word="$(echo "" >/dev/null | ${MENU} "Enter word to lookup:")"
|
||||
testword="$(dym -c -n=1 "$word")"
|
||||
|
||||
if [ "$word" != "$testword" ]; then
|
||||
keyword=$(dym -c "$word" | ${MENU} "was $word a misspelling?(select/no)")
|
||||
if [ "$keyword" = "no" ] || [ "$keyword" = "n" ]; then
|
||||
keyword="$word"
|
||||
fi
|
||||
else
|
||||
keyword="$word"
|
||||
fi
|
||||
|
||||
if ! [ "${keyword}" ]; then
|
||||
printf 'No word inserted\n' >&2
|
||||
exit 0
|
||||
fi
|
||||
$DMTERM trans -v -d "$keyword"
|
||||
}
|
||||
|
||||
mainfzf() {
|
||||
# shellcheck disable=SC2260
|
||||
word="$(echo " " | fzf --bind 'return:print-query' --prompt "Enter word to lookup:")"
|
||||
testword="$(dym -c -n=1 "$word")"
|
||||
|
||||
if [ "$word" != "$testword" ]; then
|
||||
# shellcheck disable=SC2153
|
||||
keyword=$(dym -c "$word" | ${FMENU} "was $word a misspelling?(select/no)")
|
||||
if [ "$keyword" = "no" ] || [ "$keyword" = "n" ]; then
|
||||
keyword="$word"
|
||||
fi
|
||||
else
|
||||
keyword="$word"
|
||||
fi
|
||||
|
||||
if ! [ "${keyword}" ]; then
|
||||
printf 'No word inserted\n' >&2
|
||||
exit 0
|
||||
fi
|
||||
$DMTERM trans -v -d "$keyword"
|
||||
}
|
||||
|
||||
no_opt=1
|
||||
# If script is run with '-d', it will use 'dmenu'
|
||||
# If script is run with '-f', it will use 'fzf'
|
||||
# If script is run with '-d', it will use 'rofi'
|
||||
while getopts "dfrh" arg 2>/dev/null; do
|
||||
case "${arg}" in
|
||||
d) # shellcheck disable=SC2153
|
||||
MENU=${DMENU}
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
;;
|
||||
f) # shellcheck disable=SC2153
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && mainfzf ;;
|
||||
r) # shellcheck disable=SC2153
|
||||
MENU=${RMENU}
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main "@"
|
||||
;;
|
||||
h) help ;;
|
||||
*) printf '%s\n' "Error: invalid option" "Type $(basename "$0") -h for help" ;;
|
||||
esac
|
||||
no_opt=0
|
||||
done
|
||||
|
||||
# If script is run with NO argument, it will use 'dmenu'
|
||||
[ $no_opt = 1 ] && MENU=${DMENU} && [[ "${BASH_SOURCE[0]}" == "${0}" ]] && main "$@"
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Script name: dm-documents
|
||||
# Description: Search for PDFs to open.
|
||||
# Dependencies: dmenu, fzf, rofi, zathura
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: Derek Taylor
|
||||
# HostGrady
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
# PDF_VIEWER=zathura
|
||||
files="$(find "$HOME" -maxdepth 4 -iname "*.pdf")"
|
||||
choice=$(printf '%s\n' "${files[@]}" \
|
||||
| cut -d '/' -f4- \
|
||||
| sed -e 's/Documents/Dcs/g' \
|
||||
-e 's/Downloads/Dwn/g' \
|
||||
-e 's/Pictures/Pic/g' \
|
||||
-e 's/Images/Img/g' \
|
||||
-e 's/.pdf//g' \
|
||||
| sort -g \
|
||||
| ${MENU} "File: ") || exit 1
|
||||
if [ "$choice" ]; then
|
||||
file=$(
|
||||
printf '%s' "$choice" \
|
||||
| sed -e 's/Dcs/Documents/g' \
|
||||
-e 's/Dwn/Downloads/g' \
|
||||
-e 's/Pic/Pictures/g' \
|
||||
-e 's/Img/Images/g'
|
||||
)
|
||||
"${PDF_VIEWER}" "$HOME/${file}.pdf"
|
||||
else
|
||||
echo "Program Terminated." && exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-hub
|
||||
# Description: A hub allowing you to execute all the other dmscripts.
|
||||
# Dependencies: dmenu, fzf, rofi
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: n-e0
|
||||
# Simon Ingelsson
|
||||
# Derek Taylor
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
_path=$(dirname "$(realpath "$0")")
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
function maindmenu() {
|
||||
local _self
|
||||
declare -A _scripts
|
||||
|
||||
_self=$(basename "$0")
|
||||
|
||||
while IFS= read -r -d '' script; do
|
||||
# Every 'dmscript' should contain a line that begins with "# Description: ".
|
||||
# Let's take that description and add it next to the script name in the dmenu.
|
||||
script_name=$(echo "$(basename "${script}") $(grep '^# Description: ' "${script}")" | sed 's/# Description: /- /g')
|
||||
[[ "${script_name}" == "${_self}" ]] && continue
|
||||
_scripts[${script_name}]="${script}"
|
||||
done < <(find "${_path}" -type f -regex ".*/dm-.*" -print0)
|
||||
|
||||
choice=$(printf '%s\n' "${!_scripts[@]}" | sort | grep ".*dm.*" | ${DMENU} 'Run Script:' "$@")
|
||||
|
||||
if [ "${choice}" ]; then
|
||||
thecommand="$(printf '%s' "${_scripts["${choice}"]}" | awk '{print $1}')"
|
||||
bash "$thecommand" -d "$@"
|
||||
else
|
||||
echo "Program terminated." && exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
function mainfzf() {
|
||||
local _self
|
||||
declare -A _scripts
|
||||
|
||||
_self=$(basename "$0")
|
||||
|
||||
while IFS= read -r -d '' script; do
|
||||
# Every 'dmscript' should contain a line that begins with "# Description: ".
|
||||
# Let's take that description and add it next to the script name in the dmenu.
|
||||
script_name=$(echo "$(basename "${script}") $(grep '^# Description: ' "${script}")" | sed 's/# Description: /- /g')
|
||||
[[ "${script_name}" == "${_self}" ]] && continue
|
||||
_scripts[${script_name}]="${script}"
|
||||
done < <(find "${_path}" -type f -regex ".*/dm-.*" -print0)
|
||||
|
||||
choice=$(printf '%s\n' "${!_scripts[@]}" | sort | grep ".*dm.*" | ${FMENU} 'Run Script:')
|
||||
|
||||
if [ "${choice}" ]; then
|
||||
thecommand="$(printf '%s' "${_scripts["${choice}"]}" | awk '{print $1}')"
|
||||
bash "$thecommand" -f
|
||||
else
|
||||
echo "Program terminated." && exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
function mainrofi() {
|
||||
local _self
|
||||
declare -A _scripts
|
||||
|
||||
_self=$(basename "$0")
|
||||
|
||||
while IFS= read -r -d '' script; do
|
||||
# Every 'dmscript' should contain a line that begins with "# Description: ".
|
||||
# Let's take that description and add it next to the script name in the dmenu.
|
||||
script_name=$(echo "$(basename "${script}") $(grep '^# Description: ' "${script}")" | sed 's/# Description: /- /g')
|
||||
[[ "${script_name}" == "${_self}" ]] && continue
|
||||
_scripts[${script_name}]="${script}"
|
||||
done < <(find "${_path}" -type f -regex ".*/dm-.*" -print0)
|
||||
|
||||
choice=$(printf '%s\n' "${!_scripts[@]}" | sort | grep ".*dm.*" | ${RMENU} 'Run Script:' "$@")
|
||||
|
||||
if [ "${choice}" ]; then
|
||||
thecommand="$(printf '%s' "${_scripts["${choice}"]}" | awk '{print $1}')"
|
||||
bash "$thecommand" -r "$@"
|
||||
else
|
||||
echo "Program terminated." && exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
no_opt=1
|
||||
# If script is run with '-d', it will use 'dmenu'
|
||||
# If script is run with '-f', it will use 'fzf'
|
||||
# If script is run with '-d', it will use 'rofi'
|
||||
while getopts "dfrh" arg 2>/dev/null; do
|
||||
case "${arg}" in
|
||||
d) [[ "${BASH_SOURCE[0]}" == "${0}" ]] && maindmenu ;;
|
||||
f) [[ "${BASH_SOURCE[0]}" == "${0}" ]] && mainfzf ;;
|
||||
r) [[ "${BASH_SOURCE[0]}" == "${0}" ]] && mainrofi "$@" ;;
|
||||
h) help ;;
|
||||
*) printf '%s\n' "Error: invalid option" "Type $(basename "$0") -h for help" ;;
|
||||
esac
|
||||
no_opt=0
|
||||
done
|
||||
|
||||
# If script is run with NO argument, it will use 'dmenu'
|
||||
[ $no_opt = 1 ] && [[ "${BASH_SOURCE[0]}" == "${0}" ]] && maindmenu "$@"
|
||||
|
||||
# TODO: for some reason dm-template is broken with this script, needs investigating
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-man
|
||||
# Description: Search for a manpage or get a random one.
|
||||
# Dependencies: dmenu, fzf, rofi, alacritty (edit DMTERM in dmscripts config if using another terminal)
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: Derek Taylor
|
||||
# Simon Ingelsson
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
# An array of options to choose.
|
||||
local _options=("Search manpages" "Random manpage" "Quit")
|
||||
# Piping the above array into dmenu.
|
||||
# We use "printf '%s\n'" to format the array one item to a line.
|
||||
choice=$(printf '%s\n' "${_options[@]}" | ${MENU} 'Manpages:')
|
||||
|
||||
# What to do when/if we choose one of the options.
|
||||
case "$choice" in
|
||||
'Search manpages')
|
||||
# shellcheck disable=SC2086
|
||||
man -k . | awk '{$3="-"; print $0}' \
|
||||
| ${MENU} 'Search for:' \
|
||||
| awk '{print $2, $1}' | tr -d '()' | xargs $DMTERM man
|
||||
;;
|
||||
'Random manpage')
|
||||
# shellcheck disable=SC2086
|
||||
man -k . | cut -d' ' -f1 | shuf -n 1 \
|
||||
| ${MENU} 'Random manpage:' | xargs $DMTERM man
|
||||
;;
|
||||
'Quit')
|
||||
echo "Program terminated." && exit 0
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-note
|
||||
# Description: Store multiple one-line texts or codes and copy one of them when needed.
|
||||
# Dependencies: dmenu, fzf, rofi, xclip
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: Fawzakin
|
||||
# Derek Taylor
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
# TODO: Program is broken with FZF, fix later.
|
||||
main() {
|
||||
# Picking our options.
|
||||
choice=$(printf 'Copy note\nNew note\nDelete note\nQuit' | ${MENU} 'Notes:')
|
||||
|
||||
# Choose what we should do with our choice.
|
||||
case "$choice" in
|
||||
'Copy note')
|
||||
# shellcheck disable=SC2154
|
||||
note_pick=$(${MENU} 'Copy:' <"${note_dir}")
|
||||
[ -n "${note_pick}" ] && echo "${note_pick}" | cp2cb && notify-send -u normal "Note copied" "${note_pick}"
|
||||
;;
|
||||
'New note')
|
||||
note_new=$(echo "" | ${MENU} 'Enter new note:')
|
||||
# Making sure the input is not empty and not already exist in note_dir.
|
||||
# The sed command should prevent grep from taking certain characters as a regex input.
|
||||
[ -n "$note_new" ] && ! grep -q "^$(echo "${note_new}" | sed -e 's/\[/\\[/g;s/\]/\\]/g')\$" "${note_dir}" \
|
||||
&& echo "${note_new}" >>"${note_dir}" && notify-send -u normal "Note created" "${note_new}"
|
||||
;;
|
||||
'Delete note')
|
||||
note_del=$(${MENU} 'Delete:' <"${note_dir}")
|
||||
# grep should always returns 0 regardless what happens.
|
||||
grep -v "^$(echo "${note_del}" | sed -e 's/\[/\\[/g;s/\]/\\]/g')\$" "${note_dir}" >"/tmp/dmnote" || true
|
||||
[ -n "${note_del}" ] && cp -f "/tmp/dmnote" "${note_dir}" && notify-send -u normal "Note deleted" "${note_del}"
|
||||
;;
|
||||
'Quit')
|
||||
echo "Program terminated." && exit 0
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-pipewire-out-switcher
|
||||
# Description: Switch default output for pipewire.
|
||||
# Dependencies: dmenu, fzf, rofi, pipewire, jq, pactl
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: Simon Ingelsson
|
||||
# Derek Taylor
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
get_default_sink() {
|
||||
pactl --format=json info | jq -r .default_sink_name
|
||||
}
|
||||
get_all_sinks() {
|
||||
pactl --format=json list short sinks \
|
||||
| current=$(get_default_sink) jq -r '.[] | if .name == env.current then .state="* " else .state="" end | .state + .name'
|
||||
}
|
||||
|
||||
main() {
|
||||
choice=$(printf '%s\n' "$(get_all_sinks)" \
|
||||
| sort \
|
||||
| ${MENU} 'Sink: ') || exit 1
|
||||
|
||||
if [ "$choice" ]; then
|
||||
if [[ "${choice}" == "* $(get_default_sink)" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
pactl set-default-sink "${choice}"
|
||||
notify-send "Sink is now: ${choice}"
|
||||
else
|
||||
echo "Program terminated." && exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-dictionary
|
||||
# Description: Uses didyoumean as a spellchecker.
|
||||
# Dependencies: dmenu, fzf, rofi, didyoumean
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: Francesco Prem Solidoro
|
||||
# Derek Taylor
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
WORD="$(printf '%s' "" | ${MENU} "Enter Word:")"
|
||||
|
||||
if ! [ "${WORD}" ] || [ "${WORD}" = "quit" ]; then
|
||||
printf 'No word inserted\n' >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
dym -c "$WORD" | ${MENU} "Select Correct Spelling:" | xclip -selection clipboard
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-weather
|
||||
# Description: Simple graphical weather app
|
||||
# Dependencies: dmenu, curl, yad
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: HostGrady
|
||||
# Derek Taylor
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
# Here we obtain the location from the list in the config
|
||||
# As this is loaded from other file it is technically not defined
|
||||
# shellcheck disable=SC2154
|
||||
_location="$(printf '%s\n' "${weather_locations}" | ${MENU} "Where do you want to see the weather?")"
|
||||
echo "$_location"
|
||||
|
||||
# If $weather_opts is unset, give it an empty value
|
||||
weather_opts+=''
|
||||
|
||||
# Curl wttr.in, a CLI weather app.
|
||||
# curl -s "https://wttr.in/${_location// /%20}?T&${weather_opts}" | yad --text-info --maximized
|
||||
kitty -e sh -c "curl -s 'https://wttr.in/${_location// /%20}?T&${weather_opts}'; read -n 1 -s"
|
||||
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-websearch
|
||||
# Description: Search various search engines (inspired by surfraw).
|
||||
# Dependencies: dmenu, fzf, rofi, brave (change DMMBROWSER in dmscripts config if using another browser)
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: Derek Taylor
|
||||
# Ali Furkan Yıldız
|
||||
# HostGrady
|
||||
# Simon Ingelsson
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
if [ -z "${!websearch[*]}" ]; then
|
||||
notify-send "dm-websearch: BREAKING CHANGES" "Due to breaking changes you must edit all declare statements in your config to include the g option. declare -A -> declare -Ag, declare -a -> declare -ag"
|
||||
echo "$(date): dm-websearch: BREAKING CHANGES: Due to breaking changes you must edit all declare statements in your config to include the g option.
|
||||
are -A -> declare -Ag
|
||||
are -a -> declare -ag" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 2
|
||||
exit 1
|
||||
fi
|
||||
# As this is loaded from other file it is technically not defined
|
||||
# shellcheck disable=SC2154 # Choosing a search engine by name from array above.
|
||||
engine=$(printf '%s\n' "${!websearch[@]}" | sort | ${MENU} 'Choose search engine:') || exit 1
|
||||
|
||||
# Getting the URL of the search engine we chose.
|
||||
url="${websearch["${engine}"]}"
|
||||
|
||||
# Searching the chosen engine.
|
||||
query=$(printf '%s' "$engine" | ${MENU} 'Enter search query:')
|
||||
|
||||
query="$(echo -n "${query}" | jq -s -R -r @uri)"
|
||||
# Display search results in web browser
|
||||
# shellcheck disable=SC2154
|
||||
${DMBROWSER} "${url}${query}"
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# script name: dm-wifi
|
||||
# Description: Connect to wifi using dmenu
|
||||
# Dependencies: dmenu, fzf, rofi, nmcli, Any Nerd Font
|
||||
# GitLab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributor: WitherCubes
|
||||
# Derek Taylor
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
main() {
|
||||
# TODO: Fix cut line at some point
|
||||
bssid=$(nmcli device wifi list | sed -n '1!p' | cut -b 9- | ${MENU} "Select Wifi :" | cut -d' ' -f1)
|
||||
pass=$(echo "" | ${MENU} "Enter Password :")
|
||||
# We are disabling a shellcheck warning about using && and || as it doesn't apply here.
|
||||
# shellcheck disable=SC2015
|
||||
[ -n "$pass" ] && nmcli device wifi connect "$bssid" password "$pass" || nmcli device wifi connect "$bssid"
|
||||
sleep 10
|
||||
if ping -q -c 2 -W 2 google.com >/dev/null; then
|
||||
notify-send "Your internet is working :)"
|
||||
else
|
||||
notify-send "Your internet is not working :("
|
||||
fi
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+87
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Script name: dm-youtube
|
||||
# Description: Youtube subscription manager without API access
|
||||
# Dependencies: dmenu, curl, a browser (brave by default)
|
||||
# Gitlab: https://www.gitlab.com/dwt1/dmscripts
|
||||
# License: https://www.gitlab.com/dwt1/dmscripts/LICENSE
|
||||
# Contributors: HostGrady
|
||||
# Derek Taylor
|
||||
|
||||
# Set with the flags "-e", "-u","-o pipefail" cause the script to fail
|
||||
# if certain things happen, which is a good thing. Otherwise, we can
|
||||
# get hidden bugs that are hard to discover.
|
||||
set -euo pipefail
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source ./_dm-helper.sh 2>/dev/null || source _dm-helper.sh 2>/dev/null
|
||||
|
||||
source_dmscripts_configs
|
||||
|
||||
if configs_are_different; then
|
||||
echo "$(date): configs are different" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
# this is a function for parsing youtube rss, see _dm-helper.sh for information on xmlgetnext
|
||||
parse_youtube_feed() {
|
||||
echo "$1" | while xmlgetnext; do
|
||||
case $DM_XML_TAG in
|
||||
'entry')
|
||||
title=''
|
||||
link=''
|
||||
published=''
|
||||
;;
|
||||
'media:title')
|
||||
title="$DM_XML_VALUE"
|
||||
;;
|
||||
'yt:videoId')
|
||||
link="$DM_XML_VALUE"
|
||||
;;
|
||||
'published')
|
||||
published="$(date --date="${DM_XML_VALUE}" "+%Y-%m-%d %H:%M")"
|
||||
;;
|
||||
'/entry')
|
||||
echo " ${published} | ${link} | ${title}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
local _feed_url _channel _video
|
||||
local _channel_id _video_id _video_list
|
||||
|
||||
if [ -z "${!youtube_channels[*]}" ]; then
|
||||
notify-send "dm-youtube: BREAKING CHANGES" "Due to breaking changes you must edit all declare statements in your config to include the g option. declare -A -> declare -Ag, declare -a -> declare -ag"
|
||||
echo "$(date): dm-youtube: BREAKING CHANGES: Due to breaking changes you must edit all declare statements in your config to include the g option.
|
||||
are -A -> declare -Ag
|
||||
are -a -> declare -ag" >>"$DM_CONFIG_DIFF_LOGFILE"
|
||||
sleep 2
|
||||
exit 1
|
||||
fi
|
||||
# Sorts the array and lets you select a channel with dmenu
|
||||
# As this is loaded from other file it is technically not defined
|
||||
# shellcheck disable=SC2154
|
||||
_channel=$(printf '%s\n' "${!youtube_channels[@]}" | sort | ${MENU} 'Select Channel:')
|
||||
|
||||
# The way it's done here is most effective, it searchs for "=" then it takes
|
||||
# everything before the = sign and leaves us with our variable used in the
|
||||
# _feed_url variable
|
||||
_channel_id=$(curl -s -f -L "${youtube_channels[${_channel}]}" | grep -o "channel_id=.*" | sed 's/".*//g')
|
||||
_feed_url="https://www.youtube.com/feeds/videos.xml?channel_id=${_channel_id##*=}"
|
||||
# parse rss
|
||||
_video_list=$(parse_youtube_feed "$(curl -s "${_feed_url}")")
|
||||
|
||||
_video=$(printf '%s\n' "${_video_list}" | sort -r | ${MENU} 'Select Video')
|
||||
_video_id=$(echo "${_video}" | cut -d'|' -f2 | sed -e 's/^[ \t]*//')
|
||||
|
||||
if [[ -n ${_video_id} ]]; then
|
||||
# After the video is chosen, run it in your web browser
|
||||
# shellcheck disable=SC2154
|
||||
${DMBROWSER} "https://www.youtube.com/watch?v=${_video_id}"
|
||||
fi
|
||||
}
|
||||
|
||||
MENU="$(get_menu_program "$@")"
|
||||
[[ "${BASH_SOURCE[0]}" == "${0}" ]] && main
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
BATTERY_PATH="/sys/class/power_supply/BAT0"
|
||||
|
||||
# Check if the battery is present
|
||||
if [ -d "$BATTERY_PATH" ]; then
|
||||
# Get battery status (Charging, Discharging, Full, etc.)
|
||||
status=$(cat "$BATTERY_PATH/status")
|
||||
|
||||
# Get battery percentage
|
||||
capacity=$(cat "$BATTERY_PATH/capacity")
|
||||
|
||||
# Set default icon and color
|
||||
icon=""
|
||||
color=""
|
||||
|
||||
# Determine icon based on battery status
|
||||
if [ "$status" == "Charging" ]; then
|
||||
icon="" # Charging icon
|
||||
else
|
||||
icon="" # Discharging icon
|
||||
fi
|
||||
|
||||
# Determine color based on battery percentage
|
||||
if [ "$capacity" -le 20 ]; then
|
||||
color="<fc=#f38ba8>" # Red
|
||||
elif [ "$capacity" -le 50 ]; then
|
||||
color="<fc=#fab387>" # Orange
|
||||
elif [ "$capacity" -le 79 ]; then
|
||||
color="<fc=#f9e2af>" # Yellow
|
||||
else
|
||||
color="<fc=#a6e3a1>" # Green
|
||||
fi
|
||||
|
||||
# Display battery information with icon and color
|
||||
echo "$color$icon $capacity%</fc>"
|
||||
else
|
||||
echo "Battery not found."
|
||||
fi
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Get the current brightness level as a percentage
|
||||
brightness=$(brightnessctl g)
|
||||
max_brightness=$(brightnessctl m)
|
||||
|
||||
# Perform float division and store the result with 2 decimal points
|
||||
result=$(awk "BEGIN { printf \"%.2f\", $brightness / $max_brightness }")
|
||||
|
||||
# Convert the result to a percentage (multiply by 100) and round to the nearest whole number
|
||||
percentage=$(awk "BEGIN { printf \"%.0f\", $result * 100 }")
|
||||
|
||||
# Set the icon based on the brightness level
|
||||
if [ $percentage -le 33 ]; then
|
||||
icon=""
|
||||
elif [ $percentage -le 66 ]; then
|
||||
icon=""
|
||||
else
|
||||
icon=""
|
||||
fi
|
||||
|
||||
echo "$icon $percentage%"
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
# Dependencies: pactl, awk
|
||||
|
||||
volume=$(pactl list sinks | awk '/^\s+Volume:/ {print $5}' | head -n 1 | tr -d '%')
|
||||
muted=$(pactl list sinks | awk '/^\s+Mute:/ {print $2}' | head -n 1)
|
||||
|
||||
if [ "$muted" = "yes" ]; then
|
||||
icon=""
|
||||
else
|
||||
if [ "$volume" -le 20 ]; then
|
||||
icon=""
|
||||
elif [ "$volume" -le 50 ]; then
|
||||
icon=""
|
||||
elif [ "$volume" -le 100 ]; then
|
||||
icon=""
|
||||
else
|
||||
icon=""
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$icon $volume%"
|
||||
|
||||
Reference in new issue
Block a user