Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging outputs of Hooks #10

Closed
santos-j opened this issue Apr 5, 2018 · 7 comments
Closed

Logging outputs of Hooks #10

santos-j opened this issue Apr 5, 2018 · 7 comments

Comments

@santos-j
Copy link
Contributor

santos-j commented Apr 5, 2018

Heya,

Is there any way to log the output of commands in the hooks?

I've tried to pipe them into a file, but then the commands don't appear to be executed at all

@koiuo
Copy link
Owner

koiuo commented Apr 7, 2018

Seems to be working for me.

In prior_switch hook I redirect output to a specified file

[~]$ cat ~/.config/randrctl/config.ini                                                                                                                                                        
[hooks]
prior_switch = echo "hello" > /tmp/randrctltest && echo "world" >> /tmp/randrctltest
post_switch = sh ~/.fehbg && /usr/bin/notify-send -u low "randrctl" "switched to $randr_profile"
post_fail = /usr/bin/notify-send -u critical "randrctl error" "can't switch to $randr_profile\n$randr_error"
[~]$ randrctl auto                                                                                                                                                                            
[~]$ cat /tmp/randrctltest                                                                                                                                                                    
hello
world

Let me know if this helps.

@santos-j
Copy link
Contributor Author

santos-j commented Apr 7, 2018

Hi @edio ,

You are right, it works properly. The issue was not the piping, but rather the line break between commands

Something like:

prior_switch = \
 /usr/bin/killall -SIGSTOP -q i3 && \
 /usr/bin/killall -SIGKILL -q compton 

Returns:

[ ~]$  randrctl auto 
/bin/sh: line 2: \: command not found
/bin/sh: line 2: \: command not found

Whilst:

prior_switch =  /usr/bin/killall -SIGSTOP -q i3 && /usr/bin/killall -SIGKILL -q compton 

Works like a charm

Is there any way to break lines in the hooks?

@koiuo
Copy link
Owner

koiuo commented Apr 7, 2018

I'd offer to define hook in an executable script and point randrctl to it

prior_switch = ~/.config/randrctl/hooks/priorswitch

@santos-j
Copy link
Contributor Author

santos-j commented Apr 9, 2018

Hi @edio,

That did the drill, now everything is working. Thanks a lot!

However, shouldn't randrctl support line breaks natively? Or is it a limitation of ConfigParser?

@koiuo
Copy link
Owner

koiuo commented Apr 10, 2018

@facocalj INI file does not support multi-line values, afaik.

randrctl has a dependency to pyyaml since 1.4.0, so it's be possible to introduce yaml config instead of ini (which, I believe, we should eventually do).

@santos-j
Copy link
Contributor Author

@edio,
I made the changes in #11

@santos-j
Copy link
Contributor Author

Now that we support multi line hooks, can you close the issue?

@koiuo koiuo closed this as completed Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants