sxhkd icon indicating copy to clipboard operation
sxhkd copied to clipboard

Increase maximum line length (again)

Open jallbrit opened this issue 5 years ago • 9 comments

I have a command that is very lengthy:

Super + Escape
        i3lock --ignore-empty-password --clock \
                  --image ~/Pictures/wallpapers/images/blue-red-fade.jpg --tiling \
                  --color 000000  --radius 110 --ring-width 8 --indpos "w/2:h/2" \
                  --insidecolor 30303080 --ringcolor 303030FF --linecolor 000000FF \
                  --keyhlcolor 00B75CFF \
                  --veriftext "verifying..." \
                  --insidevercolor 00000080 --ringvercolor 004a93FF --verifcolor B0B0B0FF \
                  --wrongtext "incorrect!" \
                  --insidewrongcolor 00000080 --ringwrongcolor FE1A23FF --wrongcolor B0B0B0FF \
                  --time-font "Inconsolata" --timesize 42 --timecolor E0E0E0FF \
                  --date-font "Inconsolata" --datesize 22 --datecolor E0E0E0FF \
                  --greetertext "$(fortune -s wisdom)" --greetersize 22 --greeter-font "Inconsolata" --greetercolor E0E0E0FF --greeterpos "w/2: (h/2) + r + 60"

The backslashes are simply for readability: the command is considered a single line to sxhkd.

However, due to the hard-coded line character limit, the command is cut short upon execution. I realize it is possible to instead put this single line command into a script and call the script from within sxhkdrc like this:

Super + Escape
        bash ~/bin/my-locker-script.sh

However, the need to put a single line into a script seems unnecessary. The line character limit has previously been extended, is there a reason it hasn't been extended again or why it even exists at all?

As a side note, this particular program (i3lock) is not capable of using a configuration file, so CLI arguments are the only option.

jallbrit avatar Apr 28 '19 19:04 jallbrit

I want to add that this max length doesn't only affect one command, it also limits how many sequences we can have:

super  + a ; {a,b,c,d,e,f,g,h,i,j,k,l,m,n}
   {\
   script_1.sh --lots-of-different-arguments do_something_a,\
   /very/long/path/to/the/script.sh do_something_b,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_c,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_d,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_e,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_f,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_g,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_h,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_i,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_j,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_k,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_l,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_m,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_n\
   }

The last few commands will be truncated due to the max length.

I realize one can break this into two sections, e.g.

super  + a ; {a,b,c,d,e,f,g}
   {\
   script_1.sh --lots-of-different-arguments do_something_a,\
   /very/long/path/to/the/script.sh do_something_b,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_c,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_d,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_e,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_f,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_g\
   }
super  + a ; {h,i,j,k,l,m,n}
   {\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_h,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_i,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_j,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_k,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_l,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_m,\
   /very/long/path/to/the/script.sh --lots-of-different-arguments do_something_n\
   }

However, this would be less convenient.

tsankuanglee avatar Nov 19 '19 06:11 tsankuanglee

Does anybody know the reason why the limit exists? It's annoying me VERY much.

subnut avatar Aug 02 '20 08:08 subnut

Does anybody know the reason why the limit exists? It's annoying me VERY much.

@subnut https://github.com/baskerville/sxhkd/issues/192#issuecomment-667568865

emanuele6 avatar Aug 02 '20 08:08 emanuele6

@subnut #192 (comment)

That just says it's hardcoded and intended that way. But my guess is it was just easier than manual heap allocation.

Supporting arbitrarily long commands would be nice. But at the very least we should print a warning when loading the config if a command gets cut off.

Lythenas avatar Aug 02 '20 09:08 Lythenas

if a command gets cut off.

It doesn't "get cut off" (assuming you mean that characters after the 512th get ignored). The keybind does get added at all.

emanuele6 avatar Aug 02 '20 10:08 emanuele6

It doesn't "get cut off" (assuming you mean that characters after the 512th get ignored). The keybind does get added at all.

@emanuele6 the command actually does get cut off, and the keybinding is still added. Here is a sample config you can check:

First, load this keybinding into your config:

super + F2
	echo "This is before a long line." > ~/sxhkd-log.txt; echo 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 >> ~/sxhkd-log.txt; echo This_line_will_never_be_printed >> ~/sxhkd-log.txt

In another terminal, run sxhkd:

$ sxhkd

Finally, press super + F2. In the terminal that was running sxhkd, you will see that the beginning of the final echo command is executed and the beginning of the string is printed to the terminal, but not the end of it:

$ sxhkd
This_line_will_ne

Then you can go back and check ~/sxhkd-log.txt and see that the first couple commands were executed perfectly fine:

$ cat ~/sxhkd-log.txt
This is before a long line.
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

jallbrit avatar Aug 04 '20 03:08 jallbrit

@Lythenas I think a warning from sxhkd would be great, but ideally, this character limit would just be configurable via a command-line option. At a minimum, the character limit should be documented in the sxhkd manual. I'll take a look at the code and see if I can make a pull request, but ideally I'd like to hear from @baskerville first so I know he's open to it.

jallbrit avatar Aug 04 '20 03:08 jallbrit

You are right, I was doing a bad test.

This can also be tested with

super + x
	notify-send aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b

This will send a notification with a summary containing 497 as and a body containing 1 b.

Adding an extra a to the summary will make the keybind send a notification with just a summary containing 498 as.

emanuele6 avatar Aug 04 '20 05:08 emanuele6

@emanuele6, that is certainly a much easier test, thank you.

jallbrit avatar Aug 05 '20 00:08 jallbrit