Create dmenus repo

This repository contains my various dmenu implementations.  All scripts
have been copied directly from my dotfiles:
https://gitlab.com/protesilaos/dotfiles
parents
This diff is collapsed.
My dmenu scripts
================
A collection of my dmenu[0] implementations. All those scripts have
been copied over from my dotfiles.[1] As such, they may not work
outside my custom desktop session.
License
-------
Distributed under the terms of the GNU General Public License Version
3 or later. See COPYING.
[0]: https://tools.suckless.org/dmenu/
[1]: https://gitlab.com/protesilaos/dotfiles
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Dotsmenu: a dmenu script to edit configuration files that are stored
# in a "dotfiles" directory of arbitrary depth. Opens a new terminal
# running the EDITOR on the selected file. This script is part of my
# dotfiles: https://gitlab.com/protesilaos/dotfiles.
#
# Debian Buster dependencies:
# apt install suckless-tools fd-find
#
# TODO improve documentation
# TODO review code
# TODO add feedback messages
# NOTE this would not work with the Xresources, Xdefaults, etc., though
# I do not use them…
if [ -d "$HOME/dotfiles" ]; then
my_dots="$HOME/dotfiles"
else
echo "ERROR"
echo "Your dotfiles are not available"
echo "Aborting"
exit 1
fi
my_configs() {
fdfind -H -t f '.*rc$|.*\.conf|config$' "$my_dots" | \
sed "s,$my_dots/,,g"
}
# Custom dmenu command. Accepts the line height as an argument.
my_dmenu() {
# Pass custom colours to dmenu command
source "$HOME/.local/share/my_colours/active-tempus-theme.sh"
# Get the system-wide custom font, for use in dmenu
source "$HOME/.local/share/my_custom_ui_font.sh"
if [ -n "$1" ]; then
local height="$1"
else
local height="8"
fi
dmenu -i -p 'Edit selected file' \
-nb "$background" -nf "$foreground" -sb "$color5" \
-sf "$background" -fn "$my_custom_ui_font" -l "$height"
}
# Capture the dmenu output
dotsmenu_interaction="$(my_configs | my_dmenu)"
dotsmenu_selection="$my_dots/$dotsmenu_interaction"
# Open the selected file in the editor, else exit.
# TODO add echo messages and notify-send actions. The latter require an
# extra dependency. Add it to the description.
if [ -n "$dotsmenu_interaction" ]; then
# TODO can these be turned into a case statement or something more
# elegant?
if [ -n "$EDITOR" ]; then
"$EDITOR" "$dotsmenu_selection"
elif [ -n "$VISUAL" ]; then
"$VISUAL" "$dotsmenu_selection"
elif [ -x /usr/bin/gvim ]; then
gvim "$dotsmenu_selection"
else
xdg-open "$dotsmenu_selection"
fi
else
exit
fi
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# A dmenu script to run installed Flatpak applications.
# pass custom colours to dmenu command
source "$HOME/.local/share/my_colours/active-tempus-theme.sh"
# get the system-wide custom font
source "$HOME/.local/share/my_custom_ui_font.sh"
# the customised `dmenu` command
my_dmenu() {
dmenu -i -p 'Flatpak run' -nb "$background" -nf "$foreground" \
-sb "$color6" -sf "$background" -fn "$my_custom_ui_font"
}
# select item in a list
my_flatpaks_selection() {
# We use this method instead of "flatpak list". It is faster. The
# sed ciommand removes the full file path as well as the first
# result which is the directory name containing the items we need.
find /var/lib/flatpak/app/ -maxdepth 1 -printf "%f\\n" | \
sed 's,^/.*/,, ; 1d' | my_dmenu
}
# capture dmenu output
my_flatpaks_choice=$(my_flatpaks_selection)
# get the selected flatpak's corresponding icon
# NOTE this match may require further tweaks
my_flatpaks_choice_icon="$(find /var/lib/flatpak/app/$my_flatpaks_choice \( -name "*.svg" -o -name "*.png" \) | sed 1q)"
# notify about the attempt to run the flatpak app (because these usually
# take some time to perform an initial launch).
if [ "$my_flatpaks_choice" ]; then
notify-send -i "$my_flatpaks_choice_icon" "Flatpakmenu" "Preparing to execute command:\nflatpak run <b>$my_flatpaks_choice</b>"
echo "Preparing to run:"
echo "flatpak run \"$my_flatpaks_choice\""
flatpak run "$my_flatpaks_choice" &
fi
# vi:foldmethod=marker
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# A dmenu script to provide an interface for selecting session actions.
# Possible actions are "lock", "log out", "switch users", "reboot", "poweroff".
# This script is intended to be used in a bspwm session.
# The log out option uses a bspwm-specifc command.
# See my custom working environement around bspwm:
# https://gitlab.com/protesilaos/dotfiles
# Possible actions
# ----------------------------
poweroptionsmenu_available_actions=(
"bspc quit" # log out from bspwm
"slock"
"dm-tool switch-to-greeter"
"systemctl reboot"
"systemctl poweroff"
)
# Global variables
# ----------------------------
# pass custom colours to dmenu command
source $HOME/.local/share/my_colours/active-tempus-theme.sh
# get the system-wide custom font
source $HOME/.local/share/my_custom_ui_font.sh
# Use a consistent dmenu interface
# Call this function with one argument for the prompt text
poweroptionsmenu_dmenu() {
dmenu -p "$1" -nb $background -nf $foreground -sb $color1 -sf $background -fn "$my_custom_ui_font"
}
# List actions to choose from
# ----------------------------
poweroptionsmenu_list_actions() {
# use printf to output array items on a new line
printf '%s\n' "${poweroptionsmenu_available_actions[@]}" | poweroptionsmenu_dmenu "Power options for user session"
}
poweroptionsmenu_choice=$(poweroptionsmenu_list_actions)
# Run the selected command
# ----------------------------
poweroptionsmenu_run_command() {
# make sure choice is part of available actions
# there could be an error if mistyping a string
if [[ "${poweroptionsmenu_available_actions[*]}" == *"$poweroptionsmenu_choice"* ]]; then
$poweroptionsmenu_choice
else
notify-send -i terminal "Session management" "ERROR: Option \"$poweroptionsmenu_choice\" does not exist"
exit 1
fi
}
poweroptionsmenu_run_command
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Simple Background Menu: sbgmenu is a dmenu interface for viewing
# images and/or selecting a new wallpaper from the user's "Pictures"
# directory. This script is part of my dotfiles and is primarily
# intended for use in my custom BSPWM session:
# https://gitlab.com/protesilaos/dotfiles
#
# Dependencies on Debian Buster:
# sudo apt install suckless-tools
#
# For BSPWM sessions, you also need:
# sudo apt install feh
#
# Optional dependency (binary is fdfind):
# sudo apt install fd-find
#
# Assign this script to a key binding for your convenience.
# TODO is "Pictures" automatically localised?
# TODO consider adding notify-send actions
# pass custom colours to dmenu command
source "$HOME/.local/share/my_colours/active-tempus-theme.sh"
# get the system-wide custom font
source "$HOME/.local/share/my_custom_ui_font.sh"
# the customised `dmenu` command. Accepts the prompt's text as the
# first argument and the height as a second. If the latter is not
# defined, then dmenu displays options horizontally.
my_dmenu() {
local prompt="$1"
local height="$2"
if [ -n "$2" ]; then
dmenu -i -p "$prompt" -nb "$background" -nf "$foreground" \
-sb "$color13" -sf "$background" -fn "$my_custom_ui_font" -l "$2"
else
dmenu -i -p "$prompt" -nb "$background" -nf "$foreground" \
-sb "$color13" -sf "$background" -fn "$my_custom_ui_font"
fi
}
# Here we ask the user whether they want to just view the selected
# image, or set it as the new wallpaper.
sbgmenu_mode="$(echo -e 'View images\nSet desktop wallpaper' | my_dmenu 'Choose the sbgmenu mode')"
find_pictures() {
if [ -x /usr/bin/fdfind ]; then
fdfind 'jpg|jpeg|png' "$HOME/Pictures/"
else
find "$HOME/Pictures" -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \)
fi
}
# Get image files that end in .{jpg,jpeg,png} from ~/Pictures and
# present them as dmenu items.
my_pictures_menu() {
find_pictures | my_dmenu "$1" "$2"
}
# Act depending on the mode of action.
sbgmenu_action() {
# If the option is to view an image, use the default image viewer
# (user defined).
if [ "$sbgmenu_mode" == 'View images' ]; then
sbgmenu_output="$(my_pictures_menu 'View selected picture' 10)"
echo "Opening file"
xdg-open "$sbgmenu_output"
# If the decision is to set a wallpaper, prepare the relevant
# command based on the running session. Note that the bspwm session
# is not standardised. Using `feh` is my way of doing things.
elif [ "$sbgmenu_mode" == 'Set desktop wallpaper' ]; then
sbgmenu_output="$(my_pictures_menu 'Set new desktop wallpaper' 10)"
case "$DESKTOP_SESSION" in
bspwm)
# NOTE there is no standard way for defining a wallpaper in
# BSPWM. Using a hidden file from the home dir is specific
# to my custom desktop session.
#
# Copy the selected image to the home directory, as a hidden
# file.
#
# Dependency on Debian Buster:
# sudo apt install feh
cp -f "$sbgmenu_output" "$HOME/.wallpaper.jpg"
feh --bg-fill "$HOME/.wallpaper.jpg"
;;
gnome)
gsettings set org.gnome.desktop.background picture-uri "file://$sbgmenu_output"
;;
mate)
gsettings set org.mate.background picture-filename "$sbgmenu_output"
;;
xfce)
# TODO any way to define a wallpaper in Xfce without
# specifying screen, monitor, workspace?
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/workspace0/last-image -s "$sbgmenu_output"
;;
*)
echo "ERROR. Unknown Desktop Session."
echo "Cannot set wallpaper."
echo "Aborting..."
exit 1
;;
esac
echo "Changing wallpaper to $sbgmenu_output"
# If neither of the available modes is selected, abort sbgmenu
else
exit 1
fi
}
# Run the script
sbgmenu_action
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# TODO review code 2019-02-16
# TODO update documentation
# A simple way to manage my task lisk. `stmmenu` is a dmenu interface
# for adding or removing items from a plain text file. This script is
# part of my dotfiles: https://gitlab.com/protesilaos/dotfiles
#
# Adapted from the same tool provided by suckless.org:
# https://tools.suckless.org/dmenu/scripts/todo
#
# For a command line utility with more functions and prettier output,
# which interfaces with the exact same task list file, see my `stm`. It
# is also part of my dotfiles (inside the bin directory).
# Define my task list file
if [ -f "$HOME/.my_task_list" ]; then
task_list="$HOME/.my_task_list"
else
touch -h "$HOME/.my_task_list"
task_list="$HOME/.my_task_list"
fi
# Find the number of lines (needed for dmenu -l)
task_list_height="$(grep -c '^.*' $task_list)"
# Pass custom colours to dmenu command
source "$HOME/.local/share/my_colours/active-tempus-theme.sh"
# Get the system-wide custom font, for use in dmenu
source "$HOME/.local/share/my_custom_ui_font.sh"
# Custom dmenu command. Accepts the line height as an argument.
my_dmenu() {
if [ -n "$1" ]; then
local height="$1"
else
local height="5"
fi
dmenu -i -p 'Write to add OR select to remove a task' \
-nb "$background" -nf "$foreground" -sb "$color12" \
-sf "$background" -fn "$my_custom_ui_font" -l "$height"
}
# Pipe the task list's contents to dmenu. Print line numbers as well.
task_interaction="grep -n '' $task_list | my_dmenu $task_list_height"
# Capture dmenu's output
task_action="$(eval $task_interaction)"
# Only store the line number. We need this to tell sed to delete the
# corresponding line. It avoids problems with special characters.
task_interaction_line="$(echo $task_action | cut -d ':' -f 1)"
# Do not capture the line number. That is only needed for sed and does
# not correspond to content that is present in the task list.
task_action_clean="$(echo $task_action | cut -d ':' -f 2)"
# Write to add a task, or select an existing one to remove it from the
# list.
while [ -n "$task_action" ]; do
# If item with corresponding line number exists
if grep -F "$task_action_clean" "$task_list"; then
# Remove item from list based on its line number. Also respect
# symlinks (the actual task list might be in a git-controlled
# repo).
sed -i --follow-symlinks "$task_interaction_line d" "$task_list"
# Tell us what happened
echo "Removed «$task_action_clean» from task list"
# Decrement the line height after removing the selected task
task_list_height=$(($task_list_height-1))
else
# Append new item to the task list
echo "$task_action_clean" >> "$task_list"
# Tell us what happened
echo "Appended «$task_action_clean» to task list"
# Increment the line height after adding the typed task
task_list_height=$(($task_list_height+1))
fi
# Renew stmmenu after receiving an action
task_interaction="grep -n '^.*' $task_list | my_dmenu $task_list_height"
task_action="$(eval $task_interaction)"
task_interaction_line="$(echo $task_action | cut -d ':' -f 1)"
task_action_clean="$(echo $task_action | cut -d ':' -f 2)"
done
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Description {{{
# ---------------
#
# This is a `dmenu` script to switch between Tempus themes on demand.
# It parses the list of available options and presents them once
# invoked. The choice then becomes the input/argument of another script
# that actually performs the operations pertaining to the complete theme
# change. In other words, `tempusmenu` is an interface for
# `own_script_update_environment_theme`, both of which are part of my
# dotfiles and are available in the "bin" directory. See
# https://gitlab.com/protesilaos/dotfiles (a short demo should also be
# linked to in the README.md).
#
# Tempus is a collection of themes for Vim and terminal emulators that
# is compliant *at minimum* with the WCAG AA standard for colour
# contrast between background and foreground values. See
# https://protesilaos.com/tempus-themes.
#
# Tempus is incorporated in my dotfiles, providing for all theme-related
# options it has ports for or can be implemented in. The theme change
# applies to a variety of programs, including X resources, bspwm, dunst,
# polybar, etc. A fully functional environment derived from my dotfiles
# is required for this to work as intended.
#
# Last reviewed on 2018-11-06
#
# }}}
# General variables {{{
# ---------------------
# Array with all available tempus themes. The `sed` command cleans up
# the output, stripping it of surrounding text. As for `sort`, it just
# presents the output in alphabetical order.
tempus_themes_array=$(find "$HOME/.local/share/my_colours/shell/" -type f -printf "%f\\n" | sed -e 's/tempus_\([a-z]*\).sh/\1/g' | sort)
# Pass custom colours to the `dmenu` command. These will style the
# background and foreground values using shell variables. That file is
# used in other places as well to offer a convenient way of styling
# multiple tools in a that is centralised and straightforward.
source "$HOME/.local/share/my_colours/active-tempus-theme.sh"
# Get the system-wide custom font. This is done with other `dmenu`
# scripts as well to provide for an easy way to style them all at once.
# The actual font is a `fontconfig` alias, which is currently defined as
# `Hack` and which uses my patched variant of that typeface. See my
# dotfiles under "fonts".
source "$HOME/.local/share/my_custom_ui_font.sh"
# }}}
# Functions and conditions {{{
# ----------------------------
# This is the `dmenu` wrapper with the list of available Tempus themes.
# Instead of offering a direct input source that yields an immediate
# result, this command stores the user's choice as a variable which is
# used further below.
tempus_themes_selection() {
tempus_themes_choice=$(echo -e "$tempus_themes_array" | dmenu \
-p 'Select Tempus theme' -nb "$background" -nf "$foreground" \
-sb "$color5" -sf "$background" -fn "$my_custom_ui_font")
# This checks if the input is an empty string. An empty string can
# be added by hitting the Esc key. It fixes a critical bug where
# `own_script_update_environment_theme` would be executed without
# matching an item in the Tempus Themes array. This would cause
# theme files to be replaced by an empty/invalid string. The
# necessary logic has been added to that script to tackle the issue.
if [ -z "$tempus_themes_choice" ]; then
echo 'No valid selection. Exiting...'
exit 1
fi
}
tempusmenu_confirm_input() {
tempus_themes_selection
echo "Will run desktop environment update using \"$tempus_themes_choice\""
own_script_update_environment_theme "$tempus_themes_choice" "$1"
exit 0
}
# Conditions on which to conduct the operations pertaining to the theme
# change.
tempusmenu() {
if [[ "$1" == "de" ]]; then
echo "Received 'de' as an argument for tempusmenu"
echo "Opening dmenu interface for Desktop Environment theme update"
tempusmenu_confirm_input de
elif [[ -z "$1" ]]; then
echo "There is no optional 'de' argument for tempusmenu"
echo "Opening dmenu interface for BSPWM environment update"
tempusmenu_confirm_input
else
echo "ERROR. tempusmenu accepts one optional argument: de (for use in GNOME, MATE, Xfce)"
echo "You typed \"$1\""
exit 1
fi
}
tempusmenu "$1"
# }}}
# ANNEX with further explanations {{{
# -----------------------------------
# I store my colors in "$HOME/.local/share/my_colours/". The Tempus
# themes are at $HOME/.local/share/my_colours/shell/.
#
# Recall that this is a shell script that does not use the content of
# those `*.sh`. All we need is to extract the scheme name of each item.
#
# Each theme's name is prefixed with 'tempus_' and suffixed with '.sh'.
# $ ls $HOME/.local/share/my_colours/shell/
# tempus_autumn.sh tempus_dusk.sh tempus_past.sh tempus_tempest.sh
# tempus_classic.sh tempus_fugit.sh tempus_rift.sh tempus_totus.sh
# tempus_dawn.sh tempus_future.sh tempus_spring.sh tempus_warp.sh
# tempus_day.sh tempus_night.sh tempus_summer.sh tempus_winter.sh
# The sed regex is used to omit the prefix 'tempus_' and the suffix '.sh'.
# $ find "$HOME/.local/share/my_colours/shell/" -type f -printf "%f\n" | sed -e 's/tempus_\([a-z]*\).sh/\1/g' | sort
# autumn
# classic
# dawn
# day
# dusk
# fugit
# future
# night
# past
# rift
# spring
# summer
# tempest
# totus
# warp
# winter
# }}}
# vi:foldmethod=marker
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment