Browser autostart much more simple and reliable

Big KISS lesson here!
master
Pierre Neidhardt 2013-07-28 11:48:24 +02:00
parent f9dfbfbe53
commit 59eb148402
4 changed files with 19 additions and 36 deletions

View File

@ -333,9 +333,9 @@ globalkeys = awful.util.table.join(
awful.key({ modkey, }, "e", function () awful.util.spawn(os.getenv("EDITOR")) end),
-- Directory browser
awful.key({ modkey, }, "d", function () awful.util.spawn("zshbrowser") end),
awful.key({ }, "XF86Explorer", function () awful.util.spawn(termcmd .. "ranger") end),
awful.key({ }, "XF86MyComputer", function () awful.util.spawn(termcmd .. "ranger") end),
awful.key({ modkey, }, "d", function () awful.util.spawn("browser-autostart") end),
awful.key({ }, "XF86Explorer", function () awful.util.spawn("browser-autostart") end),
awful.key({ }, "XF86MyComputer", function () awful.util.spawn("browser-autostart") end),
-- Screen lock. xlockmore is useful for LDAP login because slock does not work with it.
awful.key({ modkey, }, "s", function () awful.util.spawn_with_shell("xlock 2>/dev/null || slock") end),

11
.scripts/browser-autostart Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
## Toggle shell browser autostart and launch terminal.
if [ -z "$TERMCMD" ]; then
echo 'TERMCMD not set. Exiting.'
exit
fi
export BROWSER_AUTOSTART=true
$TERMCMD

View File

@ -1,33 +0,0 @@
#!/bin/sh
## Start terminal, invoke Zsh and launch browser automatically.
## It is important to invoke the terminal from here, and not run the terminal
## over this script, otherwise cleaning line will not run when window is killed.
if [ ! -f ~/.zshrc ]; then
echo '~/.zshrc not found. Exiting.'
exit
fi
HOOK_FILE_GREP="$(grep "HOOK_FILE=" ~/.zshrc | cut -f2 -d=)"
[ -n "$HOOK_FILE_GREP" ] && HOOK_FILE="$(eval echo "$HOOK_FILE_GREP")"
if [ -z "$HOOK_FILE" ]; then
echo 'HOOK_FILE variable could not be set. Exiting.'
exit
fi
if [ -z "$TERMCMD" ]; then
echo 'TERMCMD not set. Exiting.'
exit
fi
## We use a comment as a marker to identify the `browse' command. We need to
## make sure the `browse' command has no duplicate, and that it is removed when
## the process finishes.
[ -f "$HOOK_FILE" ] && sed -ni '/###ZSHBROWSER/!p' "$HOOK_FILE"
echo 'browse ###ZSHBROWSER' >> "$HOOK_FILE"
$TERMCMD -e zsh
[ -f "$HOOK_FILE" ] && sed -ni '/###ZSHBROWSER/!p' "$HOOK_FILE"
## Remove hook file if empty.
[ $(du "$HOOK_FILE" | cut -f1) -eq 0 ] && rm "$HOOK_FILE"

5
.zshrc
View File

@ -30,3 +30,8 @@ HOOK_FILE="$HOME/.shell.d/hook"
## Should be sourced last
[ -f "$HOOK_FILE" ] && . "$HOOK_FILE"
## Browser autostart. See .scripts/browser-autostart
if [ -n "$BROWSER_AUTOSTART" ]; then
browse
fi