summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2013-12-12 12:34:00 +0100
committerUltrabug <ultrabug@gentoo.org>2013-12-12 12:34:00 +0100
commit60e66ec8bca1f2457937e9d62e368fa7aa7a412a (patch)
treee020936698f76a239dc07b005557fffa568abc92 /examples
parenta55c2b33e7685d49449d6e3125760b0116d76d05 (diff)
new example whoami displaying the currently logged in user
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/whoami.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/whoami.py b/examples/whoami.py
new file mode 100755
index 0000000..f930991
--- /dev/null
+++ b/examples/whoami.py
@@ -0,0 +1,26 @@
+from getpass import getuser
+from time import time
+
+
+class Py3status:
+ """
+ Simply output the currently logged in user in i3bar.
+
+ Inspired by i3 FAQ:
+ https://faq.i3wm.org/question/1618/add-user-name-to-status-bar/
+ """
+ def whoami(self, i3status_output_json, i3status_config):
+ """
+ We use the getpass module to get the current user.
+ """
+ # the current user doesnt change so much, cache it good
+ CACHE_TIMEOUT = 600
+
+ # here you can change the format of the output
+ # default is just to show the username
+ username = '{}'.format(getuser())
+
+ # set, cache and return the output
+ response = {'full_text': username, 'name': 'whoami'}
+ response['cached_until'] = time() + CACHE_TIMEOUT
+ return (0, response)