Created
August 1, 2013 10:44
-
-
Save alvinfrancis/6130298 to your computer and use it in GitHub Desktop.
newsbeuter open browser script in tmux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
shellbrowser='elinks' | |
tmux_current_window=`tmux display-message -p "#W"` | |
tmux_current_pane=`tmux display-message -p "#P"` | |
# Check if in the right tmux window | |
if [ $tmux_current_window != 'news' ];then | |
elinks $1 | |
exit 0 | |
fi | |
# If the window has only one pane, create one by splitting. | |
pane_count=`tmux list-panes -F '#{line}' | wc -l` | |
if [ $pane_count -lt 2 ]; then | |
tmux split-window -h | |
fi | |
# Start my reader if it ain't running already, and send it the URL to | |
# open. | |
browser_process_count=`ps auxw | grep "$shellbrowser" | grep -cv grep` | |
if [ $browser_process_count -gt 0 ];then | |
tmux send-keys -t 1 "t" "$1" | |
tmux send -t 1 Enter | |
tmux select-pane -t $tmux_current_pane | |
else | |
tmux send-keys -t 1 "$shellbrowser \"$1\"" | |
tmux send -t 1 Enter | |
tmux select-pane -t $tmux_current_pane | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment