Skip to content

Instantly share code, notes, and snippets.

@girst
Last active April 5, 2019 19:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girst/5dbe4960330c5c56abcfc27f057aa4db to your computer and use it in GitHub Desktop.
Save girst/5dbe4960330c5c56abcfc27f057aa4db to your computer and use it in GitHub Desktop.
`jj` - i3 tool for various tasks

i3tool by github.com/girst

Blog: iStickToIt.net

This is a simple program that lets you start programs / perform common tasks with very little key strokes.

Released under the GNU GPLv2. You can download a copy of the license from GNU.org

Setup

Firstly, copy the executable into a directory in your $PATH; optionally name it jj. (from now on, /usr/bin/jj will be assumed)

To enable passwordless sudo, run sudo visudo and append this to the end of the file:

YOUR_USERNAME    ALL=(root)    NOPASSWD: /usr/bin/jj

As this essentially allows priviledge escalation, follow those steps to keep as safe as still possible:

  • make sure to only allow your main user to execute sudo from within jj without password
  • chown root:root $(which jj); chmod 0755 $(which jj), so only root can change the script

Remarks

Some things look rather ugly, like the 'lock-and-suspend' routine. let me know, if that can be expressed better.

Some of these commands need to be run as root, dnf update for example. If you have configured your sudoers file correctly, the script will detect not being superuser and restarting itself via sudo.

Even though this script is very small, I have released it as GPLv2. Part of the reason is to encourage you to share your modifications and enhancements with others.

#!/bin/bash
# i3 tool for various tasks by github.com/girst (isticktoit.net)
# Released under the GNU GPLv2; See https://www.gnu.org/licenses/gpl-2.0.txt for the full license terms and conditions.
start_mutt() {
case $1 in
*3) mutt -F ~/.mutt/startaccount2 ;;
*4) mutt -F ~/.mutt/startaccount3 ;;
*2) ;&
*) mutt -F ~/.mutt/startaccount1;;
esac
}
case $1 in
l) xscreensaver-command -lock ;;
p) poweroff ;;
r) reboot ;;
s) xscreensaver-command -lock &&\
sleep 1.5 &&\
systemctl suspend
;;
w) [ "$(id -u)" != "0" ] && sudo jj w || nmtui ;;
a) alsamixer ;;
m*) start_mutt $1 ;;
u) [ "$(id -u)" != "0" ] && sudo jj u || dnf update ;;
n)
pgrep mopidy >/dev/null 2>&1 || mopidy >/dev/null 2>&1 &
ncmpcpp
;;
*)
cat <<-EOF
Usage: $0 ACTION
Available Actions:
l lock screen
p power off
r reboot
s suspend (and lock screen)
w wifi / network manager
a alsamixer
m[234] mutt email client (account1, account2, account3)
n mopidy-spotify & ncmpcpp
u dnf update
EOF
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment