Git Product home page Git Product logo

xpub's Introduction

Xpub

License Vote for xpub

"Xpub is a Shell script to get user's display environment variables of any X graphical session from anywhere."

Perks

  • No requirement: POSIX-compliant.
  • Omniscient: Provides X environment variables of any session from any user.
  • Usefull: Run graphical commands from udevrules (see below).
  • Extra: Display graphical command on a specific session.
  • Support: XWayland users, keep calm.

Installation

  • Package (AUR)
$ yaourt -S xpub
  • Manually
$ git clone https://github.com/Ventto/xpub.git
$ cd xpub
$ chmod +x src/xpub.sh

Usage

Usage: xpub [-t TTY]

Without option, prints the X session information of the current user.

  -h:   Prints this help and exits.
  -v:   Prints the version and exits.
  -t:   prints the current TTY's user X session information.

Examples

From terminal

sudo is required.

  • Get information of your current session:
$ xpub
TTY=tty2
XUSER=alice
XAUTHORITY=/home/alice/.Xauthority
DISPLAY=:0
DBUS_SESSION_BUS_ADDRESS=/path
  • Get information of a specific session:
$ xpub -t tty2
XUSER=alice
XAUTHORITY=/home/alice/.Xauthority
DISPLAY=:0
DBUS_SESSION_BUS_ADDRESS=/path

Udev rules

IMPORT{program}="/usr/bin/xpub", \
RUN+="/bin/su $env{XUSER} -c '/usr/bin/notify-send Hello'"

After editing your rules, you may need to run udevadm control --reload-rules.

For root

$ export $(xpub) ; su "${XUSER}" -c '/usr/bin/notify-send Hello'

Shell scripts

xenv=$(xpub 2>/tmp/xpub.log)

if [ $# -ne 0 ]; then
    exit 1
else
    export ${xenv}
fi

su "${XUSER}" -c "/usr/bin/notify-send Hello"

xpub's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xpub's Issues

Does not work on fresh Ubuntu 18.04

The output of who is, for example:
user :0 2018-08-22 10:54 (:0)
without a tty, thus the grep on line 69 does not produce anything.

Upon closer examination, a bunch of other things fail too, even if correct values are hardcoded here and there. I know too little about the whole display setup to be of much help on my own.

Does not work on ubuntu

Example output on ubuntu:

root     pts/1        2018-05-29 13:52 (57.136.143.112)
  • IP changed

So who | grep tty1 returns nothing

Changes for Ubuntu 20.04

Use login-ctl to get username, use w instead of who to get display variable directly.

--- batify/xpub/src/xpub.sh	2021-03-24 20:46:54.288945317 +0100
+++ /usr/local/bin/xpub	2021-03-24 21:22:25.474690184 +0100
@@ -66,7 +66,7 @@
 
     ${tFlag} && xtty="${tArg}" || xtty="$(cat /sys/class/tty/tty0/active)"
 
-    xuser="$(who | grep "${xtty}" | head -n 1 | cut -d' ' -f1)"
+    xuser="$(loginctl list-sessions | grep "${xtty}" | awk '{print $3}' )"
 
     [ -z "${xuser}" ] && { echo "No user found from ${xtty}." 1>&2; exit 1; }
 
@@ -75,7 +75,7 @@
 
     if [ -n "${xpids}" ]; then
         for xpid in ${xpids}; do
-            xdisplay="$(ps -o cmd= "${xpid}" | grep "${vterm}" | grep -E -o ':[0-9]')"
+            xdisplay="$(w | grep "${xuser}" | grep -E -o ':[0-9]' | sort -u)"
             if [ "$?" -eq 0 ]; then
                 xdisplay="$(echo "${xdisplay}" | head -n1)"
                 break

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.