From 386a83e5846746355f55fac5a8e0db198c27457c Mon Sep 17 00:00:00 2001 From: Derek Taylor Date: Tue, 29 Jan 2019 18:22:13 -0600 Subject: [PATCH] Pushing dmenu and related scripts. --- .dmenu/dbdb.sh | 18 ++++++++++++++++++ .dmenu/dbrowse | 29 +++++++++++++++++++++++++++++ .dmenu/dmenu_edit_dwm | 20 ++++++++++++++++++++ .dmenu/dmenu_edit_st | 20 ++++++++++++++++++++ .dmenu/dmenu_running_apps | 31 +++++++++++++++++++++++++++++++ .dmenu/todo | 28 ++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+) create mode 100755 .dmenu/dbdb.sh create mode 100755 .dmenu/dbrowse create mode 100755 .dmenu/dmenu_edit_dwm create mode 100755 .dmenu/dmenu_edit_st create mode 100755 .dmenu/dmenu_running_apps create mode 100755 .dmenu/todo diff --git a/.dmenu/dbdb.sh b/.dmenu/dbdb.sh new file mode 100755 index 0000000..238c057 --- /dev/null +++ b/.dmenu/dbdb.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# dmenu-based directory browser +# to run from terminal: +# source /path/to/dbdb.sh +# or bind it to shortcut: +# echo bind \'\"\\C-o\":\"source /path/to/dbdb.sh\\n\"\' >> ~/.bashrc + +chosen="placeholder" + +while [ ! -z "$chosen" ]; do + DIRs=$( ls -a1p | grep -P '^\w[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1') + DOTDs=$( ls -a1p | grep -P '^\.[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1') + FILEs=$( ls -a1p | grep -P '^\w[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1') + DOTFs=$( ls -a1p | grep -P '^\.[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1') + clear && printf "\e[1;7;33m $(pwd) \e[0m\n$FILEs\n\e[0;38;5;238m$DOTFs\e[0m\n" + chosen=`( ( echo -e "$DIRs$DOTDs" | awk -vRS="\t" -vORS="\n" '1' ) | dmenu -i )` + cd "$chosen" +done diff --git a/.dmenu/dbrowse b/.dmenu/dbrowse new file mode 100755 index 0000000..5d6a4bb --- /dev/null +++ b/.dmenu/dbrowse @@ -0,0 +1,29 @@ +#!/bin/sh +# TODO: multisel + +target="$1" +[ -z "$target" ] && target="$(realpath .)" +prompt="$2" + +while true; do + p="$prompt" + [ -z "$p" ] && p="$target" + sel="$(ls -1a "$target" |grep -v '^\.$' | dmenu -p "$p" -l 25)" + ec=$? + [ "$ec" -ne 0 ] && exit $ec + + c="$(echo "$sel" |cut -b1)" + if [ "$c" = "/" ]; then + newt="$sel" + else + newt="$(realpath "${target}/${sel}")" + fi + + if [ -e "$newt" ]; then + target="$newt" + if [ ! -d "$target" ]; then + echo "$target" + exit 0 + fi + fi +done diff --git a/.dmenu/dmenu_edit_dwm b/.dmenu/dmenu_edit_dwm new file mode 100755 index 0000000..609cee6 --- /dev/null +++ b/.dmenu/dmenu_edit_dwm @@ -0,0 +1,20 @@ +#!/bin/bash +# ____ _____ +# | _ \_ _| Derek Taylor (DistroTube) +# | | | || | http://www.youtube.com/c/DistroTube +# | |_| || | http://www.gitlab.com/dwt1/ +# |____/ |_| +# +# Use dmenu to open and edit a file from a given list. +# I use this to quickly open my dwm source files in vim. + +# Global variables: +FILES=${1:-"/home/dt/dwm"} +DMENU='dmenu -l -i' +EDITOR='st -e vim' +# Show list of options +choice=$(ls -a "${FILES}" | $DMENU -p "« dwm » source code:") + +if [ $choice ]; then + $EDITOR ${FILES}/${choice} +fi diff --git a/.dmenu/dmenu_edit_st b/.dmenu/dmenu_edit_st new file mode 100755 index 0000000..d32b945 --- /dev/null +++ b/.dmenu/dmenu_edit_st @@ -0,0 +1,20 @@ +#!/bin/bash +# ____ _____ +# | _ \_ _| Derek Taylor (DistroTube) +# | | | || | http://www.youtube.com/c/DistroTube +# | |_| || | http://www.gitlab.com/dwt1/ +# |____/ |_| +# +# Use dmenu to open and edit a file from a given list. +# I use this to quickly open my st source files in vim. + +# Global variables: +FILES=${1:-"/home/dt/st"} +DMENU='dmenu -l -i' +EDITOR='st -e vim' +# Show list of options +choice=$(ls -a "${FILES}" | $DMENU -p "« st » source code:") + +if [ $choice ]; then + $EDITOR ${FILES}/${choice} +fi diff --git a/.dmenu/dmenu_running_apps b/.dmenu/dmenu_running_apps new file mode 100755 index 0000000..fe3c403 --- /dev/null +++ b/.dmenu/dmenu_running_apps @@ -0,0 +1,31 @@ +#!/bin/bash +# ____ _____ +# | _ \_ _| Derek Taylor (DistroTube) +# | | | || | http://www.youtube.com/c/DistroTube +# | |_| || | http://www.gitlab.com/dwt1/ +# |____/ |_| +# +# Search through open programs and switch to their tag in dwm. +# The package xorg-xlsclients is required! + +application=$( + # List all running programs + xlsclients |\ + # Fix Virtualbox and LibreOffice + sed -e 's/.*VirtualBox/foobar virtualbox/g' -e 's/.*soffice/foobar libreoffice/g' |\ + # Remove flash from results + grep -v "plugin-container" |\ + # Show only app-names + cut -d" " -f3 |\ + # Pipe to dmenu ($@ to include font settings from dwm/config.h) + dmenu -i -p "switch to:" $@ +) + +# Switch to chosen application +case $application in + gimp | truecrypt) + xdotool search --onlyvisible -classname "$application" windowactivate &> /dev/null + ;; + *) + xdotool search ".*${application}.*" windowactivate &> /dev/null +;; diff --git a/.dmenu/todo b/.dmenu/todo new file mode 100755 index 0000000..17d7415 --- /dev/null +++ b/.dmenu/todo @@ -0,0 +1,28 @@ +#!/bin/sh +# +# Write/remove a task to do later. +# +# Select an existing entry to remove it from the file, or type a new entry to +# add it. +# + +file="$HOME/.todo" +touch "$file" +height=$(wc -l "$file" | awk '{print $1}') +prompt="Add/delete a task: " + +cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file") +while [ -n "$cmd" ]; do + if grep -q "^$cmd\$" "$file"; then + grep -v "^$cmd\$" "$file" > "$file.$$" + mv "$file.$$" "$file" + height=$(( height - 1 )) + else + echo "$cmd" >> "$file" + height=$(( height + 1 )) + fi + + cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file") +done + +exit 0