Allow specifying program flags after the program

This not working has caused a lot of confusion. Not only is -f not necessary,
but the implementation is worse than just allowing flags after the program.
Deprecate the -f flag. Stop evaling a string; build an array of program options
instead.

Addresses various issues: #6, #17, #52, etc.
master
Fox Kiester 5 years ago
parent 2b1553090d
commit 4926be8fcb
No known key found for this signature in database
GPG Key ID: 316E205D6017DBFF

@ -48,7 +48,7 @@ alt + s
tdrop -ma -w -4 -y "$PANEL_HEIGHT" -s dropdown termite
#+END_EXAMPLE
The positional argument should be the name of a program in =$PATH= (as opposed to the full path to a program) and should not contain any flags (see =-f= if you want to pass additional flags to the program when running it). It should always be the last argument.
The positional argument should be the name of a program in =$PATH= (as opposed to the full path to a program). It should always come after any tdrop flags. Flags for the program can come after it (e.g. ~tdrop urxvt -title foo~).
** Basic Flags
=-w= / =--width=, =-h= / =--height=, =-x= / =--xoff=, and =-y= / =--yoff= can be used to set the window size/position. The argument to any of these can be a number (e.g. =-w 800=) or a percentage (e.g. =-w 100%=). Negative numbers correspond to that many pixels less than 100% of the screen width (e.g. =-w -4=).

38
tdrop

@ -32,6 +32,8 @@ options:
floating window; on applicable with auto_hide
-f flags specify flags/options to be used when creating the term or
window (e.g. -f '--title mytitle'; default: none).
NOTE: This flag is deprecated. Specify flags after the program name
instead. This flag may be removed in the future.
Caution: if there is a tmux session specified (with -s), the option
to execute a program (usually -e for terminal programs) is
implicitly added by tdrop
@ -88,7 +90,7 @@ dec_fix=
# set in decoration_settings
subtract_when_same=
is_floating=
program_flags=
program_flags=()
clearwid=false
cancel_auto_show=true
auto_detect_wm=false
@ -118,7 +120,7 @@ do
d) dec_fix=$OPTARG;;
S) subtract_when_same=false;;
i) is_floating=$OPTARG;;
f) program_flags=$OPTARG;;
f) eval "program_flags=($OPTARG)";;
a) auto_detect_wm=true;;
m) monitor_aware=true;;
t) pointer_monitor_detection=true;;
@ -151,7 +153,7 @@ do
decoration-fix) dec_fix=$OPTARG;;
no-subtract-when-same) subtract_when_same=false;;
is-floating) is_floating=$OPTARG;;
program-flags) program_flags=$OPTARG;;
program-flags) eval "program_flags=($OPTARG)";;
auto-detect-wm) auto_detect_wm=true;;
monitor-aware) monitor_aware=true;;
pointer-monitor-detection) pointer_monitor_detection=true;;
@ -170,6 +172,10 @@ done
shift "$((OPTIND-1))"
program=$1
if [[ -z $program_flags ]]; then
program_flags=("${@:2}")
fi
# check that the program is not a path and does not contain flags
if [[ ! $program =~ ^(current|auto_hide|auto_show|toggle_auto_hide)$ ]] && \
! type "$program" &> /dev/null; then
@ -178,8 +184,8 @@ if [[ ! $program =~ ^(current|auto_hide|auto_show|toggle_auto_hide)$ ]] && \
exit 1
fi
if [[ $# -ne 1 ]]; then
echo >&2 "Exactly 1 positional argument is required." \
if [[ -z $program ]]; then
echo >&2 "Program to run is required as a positional argument." \
"For help use -h or --help or see the manpage." | \
tee -a "$MUTDROP_PATH"/log
exit 1
@ -552,7 +558,7 @@ create_win_return_wid() {
blacklist=$(xdotool search --classname emacs)
fi
# need to redirect stdout or function won't return
eval "$1 > /dev/null &"
"$@" > /dev/null &
if [[ -z $pid ]]; then
# for normal programs
# also for when one of the programs above hadn't already been started
@ -603,30 +609,30 @@ create_win_return_wid() {
program_start() {
local program_command tmux_command wid
program_command=("$program")
if [[ $program == alacritty ]]; then
# prevent alacritty from resizing the terminal to 80x24
program_command="$program -d 0 0 $program_flags"
else
program_command="$program $program_flags"
program_command+=(-d 0 0)
fi
program_command+=("${program_flags[@]}")
if [[ -n "$session_name" ]]; then
session_name=$(printf "%q" "$session_name")
tmux_command="'tmux attach-session -dt $session_name || \
tmux_command="tmux attach-session -dt $session_name || \
tmuxifier load-session $session_name || \
tmuxinator start $session_name || \
tmux new-session -s $session_name'"
tmux new-session -s $session_name"
# note: st will work with or without the -e flag (like kitty)
# note: regular console works with or without quotes, but trinity's
# konsole only works without quotes
if [[ $program =~ ^(urxvt|alacritty|xiatec|st|lxterminal|qterminal|cool-retro-term|lilyterm|konsole$) ]]; then
program_command="$program_command -e bash -c $tmux_command"
if [[ $program =~ ^(urxvt|alacritty|xiatec|st|lxterminal|qterminal|cool-retro-term|lilyterm|konsole$) ]]; then
program_command+=(-e bash -c "$tmux_command")
elif [[ $program == kitty ]]; then
program_command="$program_command bash -c $tmux_command"
program_command+=(bash -c "$tmux_command")
else
program_command="$program_command -e \"bash -c $tmux_command\""
program_command+=(-e "\"bash -c $tmux_command\"")
fi
fi
wid=$(create_win_return_wid "$program_command")
wid=$(create_win_return_wid "${program_command[@]}")
if [[ -n "$name" ]]; then
xdotool set_window --name "$name" "$wid"
fi

@ -10,7 +10,7 @@ tdrop [\fIOPTIONS\fR] [program name or cmd]
It also has the ability to automatically hide and automatically show dropdowns. For example, it can be used to automatically hide a terminal when opening something from it, e.g. an image viewer, video player, etc. Tdrop can then automatically bring back the terminal whenever the image view, video player, etc. is closed. See the Examples section for more information.
.SH Commands
Tdrop expects the name of a program or 'current' (to use the current window) as the last argument to create a dropdown. Alternatively, it can take one of auto_show, auto_hide, or toggle_auto_hide. Neither functionality is particularly useful called directly from the command line; the former should be bound to a key, and the latter is better used in shell functions/aliases or with a file opener (e.g. in the rifle.conf).
Tdrop expects the name of a program or 'current' (to use the current window) as the last argument to create a dropdown (optionally followed by any flags to that program). Alternatively, it can take one of auto_show, auto_hide, or toggle_auto_hide. Neither functionality is particularly useful called directly from the command line; the former should be bound to a key, and the latter is better used in shell functions/aliases or with a file opener (e.g. in the rifle.conf).
.SH OPTIONS
.br
E.g.
@ -75,7 +75,11 @@ This option is a more complicated companion to -d that is also unlikely to be ne
Specify a command that will determine whether the current window is floating ($wid can be used in the command instead). Only used for the auto_hide command. This will be used to save whether the current window is floating or not. When restoring the window, if there is a float command and the window was previously floating, it will be floated. (default: none)
.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 'tdrop -f "--title mytitle" <program>' can be used. Caution: If there is a tmux session specified (with -s), the option to execute a program (usually -e for terminal programs) is implicitly added by tdrop! (default: none)
NOTE: Using this flag is deprecated; it may be removed in the future. Instead, specify program flags after the program (e.g. "tdrop kitty --name foo").
Specify flags/options that the terminal or program should be called with. For example, to set the title of the terminal, something like 'tdrop -f "--title mytitle" <program>' can be used.
Caution: If there is a tmux session specified (with -s), the option to execute a program (usually -e for terminal programs) is implicitly added by tdrop! (default: none)
.TP
\fB-a\fR, \fB --auto-detect-wm\fR
If there are available settings for the detected window manager for the -l, -L, -d, and/or -i options, automatically set them. Takes no argument. Manually specified settings take precedence. This can be used both for dropdowns and the auto_(hide|show) commands. Takes no argument. (default: false)

Loading…
Cancel
Save