You are not logged in.

#1 2014-03-14 17:42:11

djipey
Member
Registered: 2011-07-30
Posts: 159

[zsh] start a GUI and cut it from the CLI (solved)

Hi,

I'd have a tiny question. I know zsh can use prefixes to open files:

test.txt

If it is set in the .zshrc, test.txt can be opened with gedit for example. But I would like to open it with gedit, put the process in the background, and cut it from the shell.

Do you have an idea about how to do that ?

Sincerely

Last edited by djipey (2014-03-15 09:51:15)

Offline

#2 2014-03-14 21:14:44

panac
Member
Registered: 2014-03-09
Posts: 12

Re: [zsh] start a GUI and cut it from the CLI (solved)

To background a process so you can keep using the shell put an ampersand after the command

gedit &

To tell the shell not to close the application when it closes you can either run it with nohup (no-hangup signal)


nohup gedit &

or call disown afterwards


gedit &
disown

To put the process immediately in it's own process group so that it's nothing to do with the shell any more, use setsid

setsid gedit &

Offline

#3 2014-03-14 21:28:53

djipey
Member
Registered: 2011-07-30
Posts: 159

Re: [zsh] start a GUI and cut it from the CLI (solved)

Okay thanks, but I already knew how to do that. Sorry, I probably didn't explain well what I want.

For example, I have in my .zshrc:

alias -s pdf='evince'

What I would like to do is to modify this line (or use a similar trick) to afford this behavior:

test.pdf

If I write that in a shell, I would like evince to start with test.pdf as an argument, and detach the process. Am I a bit more clear ?

Offline

#4 2014-03-14 21:34:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,546
Website

Re: [zsh] start a GUI and cut it from the CLI (solved)

You can't do this with a simple alias (unless zsh has another built in options specifically for this), but you could use something like the following:

bg() {
   prog=$1
   shift
   setsid $prog $@ &
}

alias -s pdf='bg evince'

As I don't use zsh, I don't know if there would be any needed differences in the bg function as it is currently written for bash.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2014-03-14 21:41:58

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,722

Re: [zsh] start a GUI and cut it from the CLI (solved)

You might try writing a script that launches your test.pdf file using evince in the background.  Then, put that file in an alias -s in your .zshrc
Edit: I did not see Trilby's post

Last edited by ewaller (2014-03-15 15:30:32)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#6 2014-03-15 09:51:02

djipey
Member
Registered: 2011-07-30
Posts: 159

Re: [zsh] start a GUI and cut it from the CLI (solved)

Ok thank you @Trilby, I used your function with a little modification and it perfectly does the job:

bg() {
   prog=$1
   shift
   nohup setsid $prog $@ > /dev/null 2>&1
}

Thank you all

Offline

Board footer

Powered by FluxBB