Zsh - silent execution of keybind functions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zsh - silent execution of keybind functions
# 1  
Old 10-02-2014
Zsh - silent execution of keybind functions

I often need to change the gamma of my screen depending on the brightness in the room, and as I spend most of my time on a console I decided to write a couple of zsh function to do it and bind them to key input. It works, but with an undesirable side effect.

Whenever I press the keys to change the gamma, it displays the function name at the prompt and outputs the result of calling xgamma. It's easy enough to stop xgamma output when it changes, but what I really want is to stop the function name being entered into the zsh prompt and have them execute silently.

This is how I bound the keys in .zshrc:
Code:
source "${ZDOTDIR:-$HOME}/scripts/gamma/gamma"
zle -N increase_gamma
zle -N decrease_gamma
zle -N reset_gamma
bindkey -s '^{' '^qdecrease_gamma\n'
bindkey -s '^}' '^qincrease_gamma\n'
bindkey -s '^~' '^qreset_gamma\n'

These are the functions as they are declared in ~/scripts/gamma/gamma:
Code:
increase_gamma() {
    GAMMA_TEMP=$GAMMA_CURRENT
    (( GAMMA_CURRENT=$GAMMA_TEMP+0.1 ))
    xgamma -s -gamma $GAMMA_CURRENT 
}

decrease_gamma() {
    GAMMA_TEMP=$GAMMA_CURRENT
    (( GAMMA_CURRENT=$GAMMA_TEMP-0.1 ))
    xgamma -s -gamma $GAMMA_CURRENT
}

reset_gamma() {
    GAMMA_CURRENT=$GAMMA_DEFAULT
    xgamma -s -gamma $GAMMA_DEFAULT
}

GAMMA_CURRENT and GAMMA_DEFAULT are declared in .zshenv.

Is it possible to stop the functions names being displayed at the prompt when they execute, or is that something that can't be avoided?

Last edited by Caleneledh; 10-02-2014 at 08:43 PM.. Reason: Fixing page stretching due to to many spaces in code
# 2  
Old 10-02-2014
Have you considered using xbindkeys and map to shell scripts?

You could then query current gamma from the script and adjust up or down as appropriate.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

OSX read silent with prompt

A minor nitpick, but I cannot get a statement like: read -s -n 1 -p "Say Y or N here" -e ANS to actually hush the response. If I don't use the -p option, the response is silent. With it, I always see the response, and I've tried putting the -s in different spots. Is this a known issue, or... (2 Replies)
Discussion started by: jnojr
2 Replies

2. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

3. Shell Programming and Scripting

silent Input in PERL

Hello Experts, I am learning perl. I know ksh/bash/csh... In ksh I use to do this way... to read user input in silent mode so that nothing returns on the screen. stty -echo read -r pswd stty echo Please let me know the way in perl how to do it. Here are my OS and Perl Details... ... (3 Replies)
Discussion started by: explorer007
3 Replies

4. Shell Programming and Scripting

Run a script in silent mode

Hi All, I have a script which calls some other scripts.. When i run the parent script all the status messages are displaying on terminal. I want to know how to suppress dem... or run a script in silent mode Thanks, Firestar (4 Replies)
Discussion started by: firestar
4 Replies

5. Shell Programming and Scripting

Silent Background Process

I run a background process using '&'. (see example below) How can I suppress the '&' messages that are written to my console?? (lines 2 and 5) Current Output... 1 > ak@LATU ~> ls & 2 > 4000 3 > ak@LATU ~> 4 > apps/ dl/ gems/ todo/ tst/ util/ 5 > + Done ... (1 Reply)
Discussion started by: andy210
1 Replies

6. Linux

How to do a silent installation on linux

Hi, I am trying to do a silent installation of a JDk on a linux machine. Can anyone give me a command that would do it for me. Thanx Sundeep (2 Replies)
Discussion started by: eamani_sun
2 Replies

7. Linux

Wine in silent mode

I want to run through wine the utorrent and I don't want the messages that are usually displayed in the console, so I use the following command wine utorrent.exe > /dev/null & but it doesn't seem to work. Especially the redirection of the messages to the /dev/null doesn't work at all. Do... (1 Reply)
Discussion started by: myle
1 Replies

8. Shell Programming and Scripting

[Perl] Silent Input

I would like to use the WWW::Mechanize module to access a webpage that is password-protected. I was wondering if there was a way to make the input silent when asked from the script. For example: What is your password: <password> Where <password> is where you put your password, but is silent... (2 Replies)
Discussion started by: eightysix
2 Replies

9. HP-UX

SFTP silent login

Hi, I am connecting via SFTP to a remote Server. My problem is on trying to LOGin, I am asked for a password. I need to make this process automatic such that I can login without being prompted for a password. I can achieve this if the remote server has a simple FTP server and not SFTP. How... (6 Replies)
Discussion started by: sgaucho
6 Replies

10. UNIX for Dummies Questions & Answers

silent telnet

I have been using the following code for sending out an email from a AIX UNIX platform. cat filename | telnet mailhost 25 >/dev/null Time to time I get a message loopback: A specified file does not support the ioctl system call. Can anyone tell me what this means? I need this function... (1 Reply)
Discussion started by: cgardiner
1 Replies
Login or Register to Ask a Question