neXromancers / shotgun

Minimal X screenshot utility

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example not working (Window ID is not a valid integer)

foodornt opened this issue · comments

selection=$(hacksaw -f "-i %i -g %g")
shotgun $selection - | xclip -t 'image/png' -selection clipboard

Not working, outputs the error below:

Window ID is not a valid integer
Accepted values are decimal, hex (0x*), octal (0o*) and binary (0b*)

I'm on artix linux (if that means anything), the value of $selection is -i 1895 -g 438x242+476+580

What's the output with set -x active?

set -x
selection=$(hacksaw -f "-i %i -g %g")
shotgun $selection - | xclip -t 'image/png' -selection clipboard

outputs this

+preexec:0> echo -ne '\e[5 q'
+_zsh_highlight_preexec_hook:2> typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=''
+_zsh_highlight_preexec_hook:3> typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=''
+/bin/zsh:27> selection=+/bin/zsh:27> hacksaw -f '-i %i -g %g'
+/bin/zsh:27> selection='-i 23068678 -g 1039x1039+870+31'
+/bin/zsh:28> shotgun '-i 23068678 -g 1039x1039+870+31' -
+/bin/zsh:28> xclip -t image/png -selection clipboard
Window ID is not a valid integer
Accepted values are decimal, hex (0x*), octal (0o*) and binary (0b*)
+_zsh_highlight_main__precmd_hook:1> _zsh_highlight_main__command_type_cache=( )

Weird, this doesn't happen when using bash, only zsh does this for some reason

commented

The problem is to do with word splitting - this can be seen in the debug trace you posted in the line +/bin/zsh:28> shotgun '-i 23068678 -g 1039x1039+870+31' -

Bash will split the variable $selection by the spaces, but zsh will maintain the entire variable (and this value is what shotgun attempts to parse).

See this screenshot showing the two effects:
image

It appears that your shell is passing the contents of the selection variable as a single argument. This is definitely non-standard, the examples are intended to be run in a POSIX-compliant shell (as indicated by the shebang), which zsh isn't (it's mostly compatible, but I've run into issues multiple times before). It's possible that this is the result of non-default shell configuration, fwiw.

At any rate, I'm closing this because it's not a shotgun bug, but feel free to post a solution if you find one.

commented

To fix this in zsh, you could either:

  1. enable word splitting for the script in zsh
  2. change the script so it doesn't require word splitting. You could do something like:
hacksaw -f "%i %g" | read -r wid geom
echo $wid 
echo $geom

hacksaw is working properly. You have SH_WORD_SPLIT unset (see zshoptions(1)), which means that a single argument is being passed to shotgun. You can see this in your trace.

An easy fix in Zsh is to use ${=$(hacksaw -f "-i %i -g %g")} or ${(@s: :)$(hacksaw -f "-i %i -g %g")} (see zshexpn(1)).

Yep! Both of these solutions work, appreciate it!

It appears that your shell is passing the contents of the selection variable as a single argument. This is definitely non-standard, the examples are intended to be run in a POSIX-compliant shell (as indicated by the shebang), which zsh isn't (it's mostly compatible, but I've run into issues multiple times before). It's possible that this is the result of non-default shell configuration, fwiw.

This is default Zsh behavior. If you want Bourne Shell / Bash emulation, run emulate sh (see zshbuiltins(1)).