Skip to content

Commit

Permalink
Merge pull request #29 from Liupold/dev
Browse files Browse the repository at this point in the history
Dev 2.0
  • Loading branch information
Liupold authored Aug 18, 2020
2 parents 02fd8a2 + 7725fdb commit 40104a9
Show file tree
Hide file tree
Showing 8 changed files with 484 additions and 90 deletions.
13 changes: 13 additions & 0 deletions .github/make-pkgbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
version="$(cat ./version)"
echo "Deploy for version: $version on $(date)"

# make directory
mkdir -p ./aur/git ./aur/stable

# create PKGBUILDs
sed -e "s|{%version}|$version.d|g" ./aur/PKGBUILD.git.template \
> ./aur/git/PKGBUILD
sed -e "s|{%version}|$version|g" ./aur/PKGBUILD.stable.template \
> ./aur/stable/PKGBUILD

40 changes: 40 additions & 0 deletions .github/workflows/pkgbuild_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'PKBUILD'

on:
push:
branch:
- dev
pull_request:
branch:
- dev

jobs:
build-dev:
runs-on: ubuntu-latest
container:
image: archlinux
options: --privileged
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
steps:
- uses: actions/checkout@v2
- name: Build Arch Linux package (dev)
uses: FFY00/build-arch-package@master
with:
PKGBUILD: $GITHUB_WORKSPACE/aur/dev/PKGBUILD
OUTDIR: $HOME/arch-packages

build-stable:
runs-on: ubuntu-latest
container:
image: archlinux
options: --privileged
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
steps:
- uses: actions/checkout@v2
- name: Build Arch Linux package (stable)
uses: FFY00/build-arch-package@master
with:
PKGBUILD: $GITHUB_WORKSPACE/aur/stable/PKGBUILD
OUTDIR: $HOME/arch-packages
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
on:
push:
branch:
- master
- dev

name: 'Trigger: Push action'
name: 'shellcheck'
on: [push, pull_request]

jobs:
shellcheck:
Expand Down
137 changes: 98 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# A stupid simple swallower 😉.
### (Based on Process hierarchy)

Super easy to config. Written for bspwm (can be ported to other wm easily).

*Note: This new update is meant to be dropin replacement.(But it is recomended to update the bspwmrc)*
Super easy to config. Uses `xdo` WM/DE independent.

[![PKGBUILD-STATUS](https://github.com/Liupold/pidswallow/workflows/PKBUILD/badge.svg)](https://github.com/Liupold/pidswallow/actions?query=workflow%3A%22PKBUILD%22)
[![SHELLCHECK-STATUS](https://github.com/Liupold/pidswallow/workflows/shellcheck/badge.svg)](https://github.com/Liupold/pidswallow/actions?query=workflow%3A%22shellcheck%22)
[![license](https://img.shields.io/github/license/liupold/pidswallow.svg)](https://github.com/liupold/pidswallow/blob/master/LICENSE)
## Features
* Based on process hierarchy (don't care about window focus).
* cli like options. (super easy to use within scripts).
* Window Managers and Desktop Environment Independent.

```shell
pidswallow (pid swallow for bspwm)
pidswallow (pid swallow WM/DE independent)
Hides terminal window automatically, so that you don't have to
pidswallow [OPTION ...]
Expand All @@ -19,18 +22,21 @@ OPTIONS:
-s --swallow <CWID> Hides parent window of the given child window id.
-v --vomit <CWID> Unhides parent window of the given child window id.
-t --toggle <CWID> toggle between swallow and vomit. (default)
--loop listen and hide / unhide window on launch / remove.
-V --verbose Shows usefull information.
-g --glue treat if parent and child window are same. (recommended)
-l --loop listen and hide / unhide window on launch / remove.
-V --verbose Shows useful information.
bugs/issues: https://github.com/liupold/pidswallow.
```
* POSIX compliant shell script.
* Just pass in the window id of the swallower.
* Work on a toggle mode. (swallow if not swallowed else vomit).
* Super fast. (Really!) (0.02s) (faster than before).
* Super fast. (Really!) (28.0ms). (using `dash`).
```
pidswallow '0x04800003' 0.02s user 0.04s system 107% cpu 0.058 total (swallow)
pidswallow '0x04800003' 0.01s user 0.01s system 71% cpu 0.032 total (vomit)
```sh
Benchmark #1: pidswallow -s 0x02A00003
Time (mean ± σ): 28.0 ms ± 4.3 ms [User: 13.8 ms, System: 18.0 ms]
Range (min … max): 24.1 ms … 48.0 ms 74 runs
```
## Demo
Expand All @@ -44,61 +50,114 @@ pidswallow '0x04800003' 0.01s user 0.01s system 71% cpu 0.032 total (vomit)
takes wid as as arg --> gets process tree --> check blacklist --> hide parent.
```
## Dependencies
1) xargs (`find-utils`)
2) xdotool (Needed for pid -> window-id conversion).
3) xprop (Needed for window-id -> pid conversion).
4) windows needed to have `_NET_WM_PID`.
1) xdo
2) xprop (`--loop` and `--glue`).
3) xev (`--glue`).
4) xdotool (cross-workspace `--glue`, optional).
## Installation
## Using with bspwm.
### Using AUR
* stable release. (Currently on 1.0)
1) Add `pidswallow` to your path.
2) Add the following line at the end of your bspwmrc. (`~/.config/bspwmrc`)
```bash
yay -S pidswallow
```
* dev (git)
```bash
pidswallow --loop &
yay -S pidswallow-dev-git
```
3) Restart wm.
### Manual
Add `pidswallow` to your path.
## Other wm
* you need to run this script whenever a new window launches with the window id.
(use some sort of event monitor/subscription)
### Autostart
1) Launch when WM/DE starts (Example: .xinitrc, i3-config, bspwrc)
```shell
pidswallow <window-id>
```bash
pgrep -fl 'pidswallow -gl' || pidswallow -gl
```
2) Add the following to your `bashrc`, `zshrc` or shell init script. This step isn't strictly necessary, but it fixes problems with daemon-based terminals and also improves the performance of pidswallow.
**Note:** You might want to skip this step if you use Alacritty (see [Known Issues](#known-issues)).
**Note:** Your window manager has to focus new terminals as soon as they are spawned for this to work correctly.

```
[ -n "$DISPLAY" ] && command -v xdo >/dev/null 2>&1 && xdo id > /tmp/term-wid-"$$"
trap "( rm -f /tmp/term-wid-"$$" )" EXIT HUP
```

* Need to provide some way to hide the window. (or maybe minimize them).
Look into your window manager manual/docs or use `xdotool`. (ex: you can use xdotool to minimise/hide in gnome).
* Change `#*` lines in the script with your preferred way of hiding windows.
3) Restart wm and terminals.

## Blacklisting
If you want to blacklist some program you need to black list their process name. (obtained from top/ps). To the black list variable [space separated].
* no need to blacklist xev (xev will not be swallowed because it lacks `_NET_WM_PID`)
## Additional Configuration
Environment variables can be exported to change the behavior of pidswallow.

## Adding Terminals
* you can change the `swallowable` var to add term. (by default $TERMINAL is added).
The following ones accept lists of space separated process names.
* `PIDSWALLOW_SHELL`: your shell(s) (e.g `bash`). Default: Taken from `$SHELL`
* `PIDSWALLOW_TERMINAL`: your terminal(s), as fallback if shell is not used (and if terminal supports it). Default: `$TERMINAL`
* `PIDSWALLOW_BLACKLIST`: parent cannot be swallowed, (if you launch one term from another you might want to add it to blacklist). Default: same as `$PIDSWALLOW_TERMINAL`
* `PIDSWALLOW_GLUE_BLACKLIST`: not touched by `--glue`. Default: empty

## Knows Issues
* `sxiv` doesn't support this (as of now). https://github.com/muennich/sxiv/issues/398
The ones following are executed in a subshell (`/bin/sh`) and support the special strings `$pwid` and `$cwid`, holding the parent and child window IDs, respectively.
* `PIDSWALLOW_SWALLOW_COMMAND`: used to swallow (hide) windows. Default: `xdo hide $pwid`
* `PIDSWALLOW_VOMIT_COMMAND`: used to vomit (unhide) windows. Default: `xdo show $pwid`
* `PIDSWALLOW_PREGLUE_HOOK`: executed before swallowing new child window when using `--glue`. Useful for floating windows in tiled WMs. Default: empty

## Tested on
*(If you did please let me know, If it dosent work create a issue).*

* [bspwm](https://github.com/baskerville/bspwm)
* [i3](https://i3wm.org/)
* [gnome](https://www.gnome.org/gnome-3/)
* [openbox](http://openbox.org/wiki/Main_Page)
* [plasma](https://kde.org/announcements/plasma5.0/)
* [Xfce](https://www.xfce.org/)
* [herbstluftwm](https://herbstluftwm.org/) (by [cbf305](https://github.com/cbf305))

## Known Issues
* <b>sxiv</b> doesn't support this (as of now). https://github.com/muennich/sxiv/issues/398
- Solution: https://github.com/elkowar/sxiv/tree/set_net_wm_pid (use this).
* mpv (window incorrect size)
- Solution: use `--no-keepaspect-window` flag when launching.
* Alacritty won't work with the shell based approach if your shell init script is sourced too quickly. See [this](https://github.com/alacritty/alacritty/issues/2817) issue.
- Solution: fall back to terminal based approach, by skipping [Autostart step 2](#autostart)

## Tricks.
* ### Manual swallow (toggle)
## Tricks
### Manual swallow (toggle)

1) Add `pidswallow` to your path.
2) run this and click on the child window (not the term) to swallow.
```
xwininfo | awk '/Window id:/{print $4}' | tr '[a-f]' '[A-F]' | pidswallow -t
xwininfo | awk '/Window id:/{print $4}' | pidswallow -gt
```
3) or pass the window-id via keyboard shortcut. (Eg: sxhkd toggle).

```
super + v
bspc query --nodes --node focused | pidswallow -t
xdo id | pidswallow -gt
```

* Launch a program from term wihout being swallowed.
### Launch a program from term wihout being swallowed.
```
setsid -f <command> # this will not swallow the terminal.
```

## WM specific recommendations.
### bspwm
Add each set of lines to your `bspwmrc`, right before running pidswallow.
* Let bspwm handle window hiding.

```bash
export PIDSWALLOW_SWALLOW_COMMAND='bspc node $pwid --flag hidden=on'
export PIDSWALLOW_VOMIT_COMMAND='bspc node $pwid --flag hidden=off'
```
This way bspwm will remember window positions and won't lose track of swallowed windows.
* Follow `floating` state of parent (when using `--glue`).
```bash
export PIDSWALLOW_PREGLUE_HOOK='bspc query -N -n $pwid.floating >/dev/null && bspc node $cwid --state floating'
```
Check if parent window state is `floating` and apply the same to the child if that's the case.
This example should work in most cases, but feel free to add more complex hooks to your setup. (e.g. to mimic more properties of the parent).

46 changes: 46 additions & 0 deletions aur/dev/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# shellcheck disable=SC2034
# shellcheck disable=SC2154
# Maintainer: liupold <[email protected]>

pkgname=pidswallow-dev-git
pkgrel=8
pkgver=2.0.d # dev
pkgdesc="A script to swallow your terminal automatically"
arch=(x86_64)
url="https://github.com/Liupold/pidswallow/tree/dev"
license=('APACHE')
depends=(xdo xorg-xprop xorg-xev xorg-xwininfo sh)
makedepends=(git)
checkdepends=(shellcheck)
optdepends=('xdotool: Workspace/Desktop Management')
provides=(pidswallow)
conflicts=(pidswallow)

source=("$pkgname::git+https://github.com/Liupold/pidswallow")
sha256sums=("SKIP")

pkgver() {
cd "$pkgname" || return 1
{
git checkout dev
git stash
git pull
} >/dev/null 2>&1

printf "2.0.d.r%s.%s" \
"$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"

}

check() {
cd "$pkgname" || return 1
git checkout dev > /dev/null 2>&1
shellcheck "./pidswallow"
}

package() {
cd "$pkgname" || return 1
install -Dm755 "./pidswallow" "$pkgdir/usr/bin/pidswallow"
install -Dm644 "./man/pidswallow.1" "$pkgdir/usr/local/man/man1/pidswallow.1"
install -Dm644 "./README.md" "$pkgdir/usr/share/doc/$pkgname/README.md"
}
30 changes: 30 additions & 0 deletions aur/stable/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# shellcheck disable=SC2034
# shellcheck disable=SC2154
# Maintainer: liupold <[email protected]>

pkgname=pidswallow
pkgrel=2
pkgver=1.0
pkgdesc="A script to swallow your terminal automatically"
arch=(x86_64)
url="https://github.com/Liupold/pidswallow"
license=('APACHE')
depends=(xdotool)
makedepends=(git)
checkdepends=(shellcheck)
provides=(pidswallow)

source=("$pkgname-$pkgver::https://github.com/Liupold/pidswallow/archive/1.0.tar.gz")
sha256sums=("1ad08b49c9a9502bff47fd58df8b5a06252f7d349a8cdf4105932a77232adb69")


check() {
cd "$pkgname-$pkgver" || return 1
shellcheck "./pidswallow"
}

package() {
cd "$pkgname-$pkgver" || return 1
install -Dm755 "./pidswallow" "$pkgdir/usr/bin/pidswallow"
install -Dm644 "./README.md" "$pkgdir/usr/share/doc/$pkgname/README.md"
}
Loading

0 comments on commit 40104a9

Please sign in to comment.