Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jcinis/i3blocks-contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
jcinis committed Jun 2, 2021
2 parents ef9fe4a + 697cbd2 commit db2ef7b
Show file tree
Hide file tree
Showing 157 changed files with 10,661 additions and 260 deletions.
46 changes: 23 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# How to contribute

So you've written a blocklet for i3blocks and would like to share it with the
So you've written a blocklet for i3blocks and would like to share it with the
community, great! Let's just set a few ground rules in order to get your
blocklet included.
blocklet included.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
interpreted as described in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt).

# Directory guidelines

1. A blocklet MUST be confined to a single directory and the name of the
1. A blocklet MUST be confined to a single directory and the name of the
directory MUST be relevant to the blocklet's purpose or core feature.
2. A blocklet MUST be human readable.
3. A blocklet MUST contain a `README.md` explaining what the blocklet does,
what its dependencies are, and any special instruction or setup required to
use it.
4. A suggested i3blocks configuration MUST be included in an `i3blocks.conf`
4. A suggested i3blocks configuration MUST be included in an `i3blocks.conf`
file or within the `README.md`.
5. Any non-obvious assumptions required to make the configuration work SHOULD
5. Any non-obvious assumptions required to make the configuration work SHOULD
be included either in the `README.md` or as comments in the configuration.
6. A blocklet's suggested command SHOULD be of the form
`command=$SCRIPT_DIR/myscript [args...]` even
if the script is a single line. The [args...] SHOULD be empty, in favor of
using injected properties.
7. The command file (`myscript` above) SHOULD be the entirety of the
executable part of your blocklet, i.e. your code is a single script.
8. The command file's name, SHOULD match the name of the
8. The command file's name, SHOULD match the name of the
containing directory. E.g. `myscript/myscript`
is a good name, but `myscript/yourscript` is not.
9. A blocklet SHOULD NOT have a separate non `i3blocks.conf` configuration
file. Any extra configuration (e.g. default colors, paths, etc.) SHOULD be
file. Any extra configuration (e.g. default colors, paths, etc.) SHOULD be
injected properties.
10. A blocklet MUST include at least one screenshot of what it looks like in
action.
Expand All @@ -53,50 +53,50 @@ interpreted as described in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt).
2. A contributor with write access MUST NOT merge any pull request that he or
she created, unless there are no other contributors with write access
currently active.
3. Commit messages SHOULD be written in imperative form. E.g.
3. Commit messages SHOULD be written in imperative form. E.g.
`myscript: add option to configure colors`, instead of
`myscript: added option to configure colors`.
4. Commit message first lines SHOULD be 72 characters or less but descriptive,
4. Commit message first lines SHOULD be 72 characters or less but descriptive,
and details MAY be added to subsequent lines.
5. Commit details SHOULD write `Fixes: [issue]` or `Closes: [issue]` if
the commit is meant to fix/close an issue on the issues page.
6. A pull request SHOULD contribute significant change to exactly one
blocklet. A bug fix or new injected property will usually be considered
blocklet. A bug fix or new injected property will usually be considered
a significant change.

# Example workflow

In case you have never made a pull request before, here is an example workflow.

1. You write and test your blocklet called `myscript`.
2. You write a `README.md` and `i3blocks.conf` to go with your script, make a
`screenshot.png` and put `myscript`, `README.md`, `i3blocks.conf`,
2. You write a `README.md` and `i3blocks.conf` to go with your script, make a
`screenshot.png` and put `myscript`, `README.md`, `i3blocks.conf`,
`screenshot.png`, and your favorite `LICENSE` into a
directory called `myscript`.
3. You fork the i3blocks-contrib repository on github, and clone your fork of
i3blocks-contrib onto your computer with `git clone [your fork here]`.
4. You copy your `myscript` directory to the top level of the cloned
i3blocks-contrib directory and `cd` to the top level directory.
5. You `git add myscript` to tell git to track your blocklet's directory, you
5. You `git add myscript` to tell git to track your blocklet's directory, you
will need to do this before every commit.
6. You `git commit` and leave a commit message of the form
`myscript: add myscript, a short description of myscript`
7. Perhaps you make a few last minute changes, and add another commit.
8. You squash your commits into one with `git rebase -i` and follow the
instructions, leaving only your first commit and commits that were already
instructions, leaving only your first commit and commits that were already
there unsquashed.
9. You push your changes to your fork on github with `git push`.
10. You navigate to vivien's i3blocks-contrib, click "pull requests" and
"New pull request". You click "compare across forks", then select the base
as vivien's i3blocks-contrib and the head fork as yours. You click
"New pull request". You click "compare across forks", then select the base
as vivien's i3blocks-contrib and the head fork as yours. You click
"Create pull request".
11. The community makes some comments and suggests some things to improve before
11. The community makes some comments and suggests some things to improve before
your blocklet is accepted.
12. You add and commit changes to your local copy, and then squash them as before, so
12. You add and commit changes to your local copy, and then squash them as before, so
that there are only two commits besides those that were there when you first
forked, your initial commit and one representing all the changes made to
forked, your initial commit and one representing all the changes made to
address community concerns.
13. You push to your remote fork of i3blocks-contrib, and the changes
13. You push to your remote fork of i3blocks-contrib, and the changes
automatically get incorporated into the pull request process.
14. A maintainer with write access to vivien's i3blocks-contrib decides your
script is ready to be merged and merges it in, possibly making minor changes
Expand All @@ -107,7 +107,7 @@ squash your local commits since your last pull request and replace the commit
message with something of the form

myscript: what has changed since last pull request

More detailed description of changes, perhaps including:
Change 1
Change 2
Expand Down
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
PREFIX = $(HOME)/.local/

_INSTALLDIR = $(DESTDIR)$(PREFIX)/libexec/i3blocks/

_MAKEBLOCKS := $(dir $(wildcard */Makefile))
all: build
build: $(_MAKEBLOCKS)
$(_MAKEBLOCKS):
$(MAKE) -C $@

install: all do-install

installdirs:
install -d $(_INSTALLDIR)

_BLOCKS := $(shell find . -type f -executable -not -path './.*')

do-install: installdirs $(_BLOCKS)
$(_BLOCKS):
install -m755 $@ $(_INSTALLDIR)

uninstall:
rm -f $(foreach block,$(_BLOCKS),$(_INSTALLDIR)$(notdir $(block)))

.PHONY: $(_MAKEBLOCKS) $(_BLOCKS) build do-install all install uninstall
7 changes: 6 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ This repository contains a set of scripts (a.k.a. *blocklets*) for link:https://
| link:apt-upgrades[] | Show system upgrades using aptitude
| link:arch-update[] | Show AUR updates using yaourt
| link:aur-update[] | Show AUR updates
| link:backlight[] | Show the screen brightness value given by `xbacklight`
| link:bandwidth[] | Show bandwidth information (default bash version)
| link:bandwidth2[] | Show bandwidth information (C version)
| link:bandwidth3[] | Show bandwidth information (another bash version)
| link:battery-poly[] | Show multi-battery info
| link:battery[] | Show battery info
| link:battery2[] | Pretty battery info
| link:batterybar[] | Show battery info graphically as a bar
Expand All @@ -22,12 +24,14 @@ This repository contains a set of scripts (a.k.a. *blocklets*) for link:https://
| link:docker[] | Show the number of Docker containers and container IP
| link:dunst[] | Toggle Dunst notifications using a simple Do-Not-Disturb button
| link:email[] | Show the number of unread IMAP messages
| link:essid[] | Show the wifi ESSID you are connected to
| link:essid[] | Show the wifi ESSID you are connected to (dep: iwconfig, perl)
| link:gpu-load[] | Shows load of Nvidia GPUs
| link:go[] | Show the currently installed Go version
| link:iface[] | Show network interface IP/status
| link:kbdd_layout[] | Show the keyboard layout using dbus and kbdd
| link:keyindicator[] | Show the status of capslock or numlock
| link:key_layout[] | Show the current keyboard layout using setxkbmap
| link:key_light[] | Control the keyboard backlight
| link:kubernetes[] | Show the kubernetes current context and namespace
| link:load_average[] | Show the system 1 minute load average
| link:mediaplayer[] | Generic media player status/controls using playerctl
Expand All @@ -40,6 +44,7 @@ This repository contains a set of scripts (a.k.a. *blocklets*) for link:https://
| link:tahoe-lafs[] | Show status of your tahoe-lafs grid
| link:temperature[] | Show system temperatures using lm-sensors
| link:time[] | Show the current date/time and click to change timezones
| link:ssid[] | Show the wifi SSID you are connected to (dep: iw, awk)
| link:usb[] | Show connected usb storage device info
| link:volume[] | Show the current system volume (default)
| link:volume-pulseaudio[] | Pretty print system volume for pulseaudio
Expand Down
18 changes: 15 additions & 3 deletions arch-update/arch-update
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ def create_argparse():


def get_updates():
output = check_output(['checkupdates']).decode('utf-8')
output = ''
try:
output = check_output(['checkupdates']).decode('utf-8')
except subprocess.CalledProcessError as exc:
# checkupdates exits with 2 and no output if no updates are available.
# we ignore this case and go on
if not (exc.returncode == 2 and not exc.output):
raise exc
if not output:
return []

Expand Down Expand Up @@ -112,8 +119,13 @@ if args.aur:

update_count = len(updates)
if update_count > 0:
info = str(update_count) + ' updates available'
short_info = str(update_count) + ' updates'
if update_count == 1:
info = str(update_count) + ' update available'
short_info = str(update_count) + ' update'
else:
info = str(update_count) + ' updates available'
short_info = str(update_count) + ' updates'

matches = matching_updates(updates, args.watch)
if matches:
info += ' [{0}]'.format(', '.join(matches))
Expand Down
4 changes: 4 additions & 0 deletions aur-update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ Example i3blocks configuration:
[aur-update]
command=$SCRIPT_DIR/aur-update
markup=pango
format=json
interval=43200
UPDATE_COLOR=red
QUIET=1
IGNORE=root vidyodesktop
#CACHE_UPDATES=0
```

Right or middle click sends a notification (via notify-send) with a list of outdated packages
and the corresponding version information.
If you enable caching (`CACHE_UPDATES=1`), the update list will be cached as an environment variable.
This will be read on a (right/middle) click to directly show the notification without the delay caused by updating the list.


## Dependencies
Expand Down
30 changes: 25 additions & 5 deletions aur-update/aur-update
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import json
import os
import requests
import subprocess as sp
Expand All @@ -41,6 +42,7 @@ args = Args()
args.add_argument('UPDATE_COLOR', 'yellow')
args.add_argument('QUIET', False, bool)
args.add_argument('IGNORE', [], list)
args.add_argument('CACHE_UPDATES', False, bool)


def version_in_aur(pkg):
Expand Down Expand Up @@ -74,6 +76,14 @@ def vcs_version(pkg, ver):
return None


# show the list of updates already cached
if args.cache_updates and block_button in [2, 3]:
if '_update_cache' in os.environ:
updates = os.environ['_update_cache']
else:
updates = 'no updates cached'
sp.call(['notify-send', 'AUR updates', updates or 'up to date'])

# get list of foreign packages -- assumed to be from the AUR
packages = sp.check_output(['pacman', '-Qm']).decode('utf8')

Expand All @@ -93,15 +103,25 @@ for pkg in installed_version.keys():
if vcs_version(pkg, v_aur) != vcs_version(pkg, v_inst):
updates.append(pkg + ' (%s -> %s)' % (v_inst, v_aur))

# create the message for the block
n_updates = len(updates)
if n_updates > 0:
msg = "<span color='{0}'>{1} AUR updates</span>"
print(msg.format(args.update_color, n_updates))
msg = "<span color='{0}'>{1} AUR updates</span>".format(args.update_color, n_updates)
elif not args.quiet:
print('AUR up to date')
msg = 'AUR up to date'

# turn it into a json message
msg = {'full_text': msg}

# cache the new updates list
if args.cache_updates:
msg['_update_cache'] = '\n'.join(updates)

print(json.dumps(msg))

if block_button in [2, 3]:
sp.call(['notify-send', 'AUR updates', '\n'.join(updates)])
# if you don't use caching, show the new list of updates
if not args.cache_updates and block_button in [2, 3]:
sp.call(['notify-send', 'AUR updates', '\n'.join(updates) or 'up to date'])

if not 'BLOCK_NAME' in os.environ and n_updates > 0:
# not called by i3blocks: show the complete list
Expand Down
Loading

0 comments on commit db2ef7b

Please sign in to comment.