Skip to content

Commit

Permalink
Darwin support
Browse files Browse the repository at this point in the history
  • Loading branch information
rda3mon committed Jul 8, 2022
1 parent 2f99b9e commit 59c4a24
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
48 changes: 33 additions & 15 deletions plugins/scripts/process_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,39 @@ if [ -z $ppid ] || ! [[ $ppid =~ $re ]]; then
exit 0
fi

pid=$(ps --no-headers --ppid $ppid -o pid)
current_pid=$$

pid="${pid[@]/$current_pid}"

full_command=$(ps --no-headers --ppid $ppid -o command)
pid_command=$(ps --no-headers --ppid $ppid -o pid)
cpu_command=$(ps --no-headers --ppid $ppid -o %cpu)
memory_command=$(ps --no-headers --ppid $ppid -o %mem)
top_command=$(ps --no-headers -A -o %cpu:3,%mem:3,comm --sort=-%cpu,-%mem | head -1)
if [ -z $pid ]; then
full_command=$(ps --no-headers --pid $ppid -o command)
pid_command=$(ps --no-headers --pid $ppid -o pid)
cpu_command=$(ps --no-headers --pid $ppid -o %cpu)
memory_command=$(ps --no-headers --pid $ppid -o %mem)
if [ "$(uname)" == "Darwin" ]; then
pid=$(pgrep -P $ppid)
current_pid=$$

pid="${pid[@]/$current_pid}"

full_command=$(ps -p $pid -o command | sed 1d)
pid_command=$pid
cpu_command=$(ps -p $pid -o %cpu | sed 1d)
memory_command=$(ps -p $pid -o %mem | sed 1d)
if [ -z $pid ]; then
full_command=$(ps -p $ppid -o command | sed 1d)
pid_command=$ppid
cpu_command=$(ps -p $ppid -o %cpu | sed 1d)
memory_command=$(ps -p $ppid -o %mem | sed 1d)
fi
else
pid=$(ps --no-headers --ppid $ppid -o pid)
current_pid=$$

pid="${pid[@]/$current_pid}"

full_command=$(ps --no-headers --ppid $ppid -o command)
pid_command=$(ps --no-headers --ppid $ppid -o pid)
cpu_command=$(ps --no-headers --ppid $ppid -o %cpu)
memory_command=$(ps --no-headers --ppid $ppid -o %mem)
top_command=$(ps --no-headers -A -o %cpu:3,%mem:3,comm --sort=-%cpu,-%mem | head -1)
if [ -z $pid ]; then
full_command=$(ps --no-headers --pid $ppid -o command)
pid_command=$(ps --no-headers --pid $ppid -o pid)
cpu_command=$(ps --no-headers --pid $ppid -o %cpu)
memory_command=$(ps --no-headers --pid $ppid -o %mem)
fi
fi

if [ $cmd == 'ssh' ]; then
Expand Down
12 changes: 8 additions & 4 deletions plugins/scripts/ssh_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ if [ -z $ppid ] || ! [[ $ppid =~ $re ]] || [ $cmd != 'ssh' ]; then
exit 0
fi

pid=$(ps --no-headers --ppid $ppid -o pid)
current_pid=$$

if [ "$(uname)" == "Darwin" ]; then
pid=$(pgrep -P $ppid)
current_pid=$$
else
pid=$(ps --no-headers --ppid $ppid -o pid)
current_pid=$$
fi
pid="${pid[@]/$current_pid}"

if [ -z $pid ]; then
echo ""
else
echo "| CMD:$(ps --no-headers --ppid $ppid -o pid) "
echo "| CMD:$(ps -p $pid -o pid) | sed 1d"
fi
4 changes: 2 additions & 2 deletions tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ bind -n C-Down select-pane -D
#bind M-1 send-keys -t. 'mvn install' Enter

# Duplicate the command from current pane(including ssh)
bind C-D run-shell 'tmux split-window -v "$(ps --no-headers --ppid #{pane_pid} -o command || ps --no-headers --pid #{pane_pid} -o command); bash"'
bind C-F run-shell 'tmux split-window -h "$(ps --no-headers --ppid #{pane_pid} -o command || ps --no-headers --pid #{pane_pid} -o command); bash"'
bind C-D run-shell 'tmux split-window -v "$(ps --no-headers --ppid #{pane_pid} -o command 2> /dev/null || pid=$(pgrep -P #{pane_pid}); ps -p $pid -o command | sed 1d); bash"'
bind C-F run-shell 'tmux split-window -h "$(ps --no-headers --ppid #{pane_pid} -o command 2> /dev/null || pid=$(pgrep -P #{pane_pid}); ps -p $pid -o command | sed 1d); bash"'

# Log pane output to temp file
bind C-P pipe-pane -o "cat >>/tmp/#{pane_pid}_tmux.log" \; display "Toggled logging to /tmp/tmux_#{pane_pid}.log"
Expand Down

0 comments on commit 59c4a24

Please sign in to comment.