From ae9083e695f0f94b0a9af207acf2af0661894ea3 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Sat, 20 Sep 2014 23:53:51 +0200 Subject: [PATCH] Implement save command strategy: pgrep --- CHANGELOG.md | 1 + save_command_strategies/pgrep.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 save_command_strategies/pgrep.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b7d126..9f737f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### master - plugin now uses strategies when fetching pane full command. Implemented 'default' strategy. +- save command strategy: 'pgrep'. It's here only if fallback is needed. ### v1.3.0, 2014-09-20 - remove dependency on `pgrep` command. Use `ps` for fetching process names. diff --git a/save_command_strategies/pgrep.sh b/save_command_strategies/pgrep.sh new file mode 100755 index 0000000..15d98b3 --- /dev/null +++ b/save_command_strategies/pgrep.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +PANE_PID="$1" + +exit_safely_if_empty_ppid() { + if [ -z "$PANE_PID" ]; then + exit 0 + fi +} + +full_command() { + \pgrep -lf -P "$PANE_PID" | + cut -d' ' -f2- +} + +main() { + exit_safely_if_empty_ppid + full_command +} +main