You are not logged in.
Hi,
I'd have a tiny question. I know zsh can use prefixes to open files:
test.txtIf 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
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 &
disownTo 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
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.pdfIf 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
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
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
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