diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index f4b5c686..2cafe944 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -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), diff --git a/.scripts/browser-autostart b/.scripts/browser-autostart new file mode 100755 index 00000000..f3f4da3b --- /dev/null +++ b/.scripts/browser-autostart @@ -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 diff --git a/.scripts/zshbrowser b/.scripts/zshbrowser deleted file mode 100755 index 1081ddeb..00000000 --- a/.scripts/zshbrowser +++ /dev/null @@ -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" diff --git a/.zshrc b/.zshrc index f5e36356..077da941 100644 --- a/.zshrc +++ b/.zshrc @@ -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