From b21f9b8add4bb23afcfe6097be5c157e80134897 Mon Sep 17 00:00:00 2001 From: noctuid Date: Sun, 30 Aug 2015 14:03:23 -0400 Subject: [PATCH] Add -f option to specify options for the terminal or other program to be created using Addresses #6 --- tdrop | 26 ++++++++++++++++++++------ tdrop.groff | 3 +++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/tdrop b/tdrop index 7034ea5..00b3973 100755 --- a/tdrop +++ b/tdrop @@ -23,6 +23,7 @@ options: -d XxY give decoration/border size to accurately save position; only applicable with auto_show; on applicable with a few window managers (e.g. blackbox) -z use a different sleep time to wait for terminal to be created (advanced; see man page) -Z use a different sleep time for -W program to be created (advanced; see man page) + -f specify flags/options to be used when creating the term or window (e.g. -f '--title mytitle', default: none) -a automatically detect window manager and if settings exist for it, automatically set -p, -P, and -d values as necessary; this can have affect when used with a terminal or with auto_show or auto_hide (default: false) -m for use with multiple monitors and only with dropdowns (not for auto_show or auto_hide); convert percentages used for width or height to values relative to the size of the current monitor and force reszing of the dropdown when the monitor changes (default: false) -W the given program is not a terminal (or lacks an -e flag) (default: assume it IS a terminal) @@ -60,13 +61,14 @@ sleep_term_time=0.01 sleep_term_user_set=false sleep_win_time=0.5 sleep_win_user_set=false +program_flags="" normal_window=false clearwid=false cancel_auto_show=true term=${*:0-1} auto_detect_wm=false multiple_monitors=false -while getopts :h:w:x:y:s:n:p:P:M:O:d:z:Z:-:Wam opt +while getopts :h:w:x:y:s:n:p:P:M:O:d:z:Z:f:-:Wam opt do case $opt in h) height=$OPTARG;; @@ -84,6 +86,7 @@ do sleep_term_user_set=true;; Z) sleep_win_time=$OPTARG sleep_win_user_set=true;; + f) program_flags=$OPTARG;; W) normal_window=true;; a) auto_detect_wm=true;; m) multiple_monitors=true;; @@ -106,6 +109,7 @@ do sleep_term_user_set=true;; sleep-window) sleep_win_time=$OPTARG sleep_win_user_set=true;; + program-flags) program_flags=$OPTARG;; normal-window) normal_window=true;; auto-detect-wm) auto_detect_wm=true;; multiple-monitors) multiple_monitors=true;; @@ -386,27 +390,37 @@ maybe_cancel_auto_show() { # term_create() { + if [[ -n $program_flags ]]; then + term_command="$term $program_flags" + else + term_command=$term + fi if [[ -n $session_name ]]; then # ugly workarounds due to how different terms different -e flags work if [[ $term == urxvt ]]; then - $term -e bash -c "sleep $sleep_term_time && xdotool getactivewindow > /tmp/tdrop/$term$num && xdotool getactivewindow windowmove $xoff $yoff windowsize $width $height && tmux attach-session -dt $session_name || tmuxinator start $session_name || tmux new-session -s $session_name" & + $term_command -e bash -c "sleep $sleep_term_time && xdotool getactivewindow > /tmp/tdrop/$term$num && xdotool getactivewindow windowmove $xoff $yoff windowsize $width $height && tmux attach-session -dt $session_name || tmuxinator start $session_name || tmux new-session -s $session_name" & else # starting with '/bin/bash -c' because required by termite - $term -e "/bin/bash -c 'sleep $sleep_term_time && xdotool getactivewindow > /tmp/tdrop/$term$num && xdotool getactivewindow windowmove $xoff $yoff windowsize $width $height && tmux attach-session -dt $session_name || tmuxinator start $session_name || tmux new-session -s $session_name'" & + $term_command -e "/bin/bash -c 'sleep $sleep_term_time && xdotool getactivewindow > /tmp/tdrop/$term$num && xdotool getactivewindow windowmove $xoff $yoff windowsize $width $height && tmux attach-session -dt $session_name || tmuxinator start $session_name || tmux new-session -s $session_name'" & fi else # not using hold, because flag is different for different terminals if [[ $term == urxvt ]]; then - $term -e bash -c "sleep $sleep_term_time && xdotool getactivewindow > /tmp/tdrop/$term$num && xdotool getactivewindow windowmove $xoff $yoff windowsize $width $height && $SHELL" & + $term_command -e bash -c "sleep $sleep_term_time && xdotool getactivewindow > /tmp/tdrop/$term$num && xdotool getactivewindow windowmove $xoff $yoff windowsize $width $height && $SHELL" & else # not using hold, because flag is different for different terminals - $term -e "/bin/bash -c 'sleep $sleep_term_time && xdotool getactivewindow > /tmp/tdrop/$term$num && xdotool getactivewindow windowmove $xoff $yoff windowsize $width $height && $SHELL'" & + $term_command -e "/bin/bash -c 'sleep $sleep_term_time && xdotool getactivewindow > /tmp/tdrop/$term$num && xdotool getactivewindow windowmove $xoff $yoff windowsize $width $height && $SHELL'" & fi fi } win_create() { - $term & + if [[ -n $program_flags ]]; then + win_command="$term $program_flags" + else + win_command=$term + fi + $win_command & # need to wait for window to be created sleep $sleep_win_time # often pids have two wids diff --git a/tdrop.groff b/tdrop.groff index 15c7954..6ee31dd 100644 --- a/tdrop.groff +++ b/tdrop.groff @@ -57,6 +57,9 @@ Specify an alternate sleep time to wait for a terminal emulator to be completed. \fB\-Z\fR, \fB \-\-sleep-window\fR Specify an alternate sleep time to wait for a window to be completed. This is for use with -W or for -a with tiling window managers that cannot pre-float the next instance of a window (e.g. awesome and i3 if no rule to always float a specific class). Only use this option if tdrop ends up capturing a different window as the dropdown when you press a dropdown key. You probably won't need to change this, and if you do, please report it. I hope to remove the need for sleeping entirely in the future. (default: 0.5) .TP +\fB\-f\fR, \fB \-\-program-flags\fR +Specify flags/options that the terminal or program should be called with. For example, to set the title of the terminal, something like '-f "--title mytitle"' can be used. (default: none) +.TP \fB\-W\fR, \fB \-\-normal-window\fR Specifies that the program is not a terminal or does not have the '-e' flag; takes no argument. If using 'tdrop current', this option will have no effect either way. (default: false) .TP