From b87063b27e0ca6f87fdfb0eff9166ba24ac2cacb Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 25 Apr 2017 02:40:45 -0400 Subject: [PATCH] Add [unix-]OS-agnostic bin/open + shell/tmux/bin/tmux-session-name --- bin/open | 12 ++++++++++++ os/arch/aliases.zsh | 2 -- shell/tmux/bin/tmux-session-name | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100755 bin/open create mode 100755 shell/tmux/bin/tmux-session-name diff --git a/bin/open b/bin/open new file mode 100755 index 00000000..9a9cec3a --- /dev/null +++ b/bin/open @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +case $OSTYPE in + darwin*) open $@ ;; + linux*) xdg-open $@ ;; +esac + +# OPTIONAL: requires bin/tmux +if command -v 'tmux-session-name' >/dev/null; then + # If this was used from a scratch tmux terminal, close it + [[ "$(tmux-session-name)" == scratch ]] && tmux kill-session -t scratch +fi diff --git a/os/arch/aliases.zsh b/os/arch/aliases.zsh index a4423425..e586e60e 100644 --- a/os/arch/aliases.zsh +++ b/os/arch/aliases.zsh @@ -1,7 +1,5 @@ alias ls="${aliases[ls]:-ls} --color=auto --group-directories-first" -alias open='xdg-open' - alias sys='systemctl' alias sys!='sudo systemctl' diff --git a/shell/tmux/bin/tmux-session-name b/shell/tmux/bin/tmux-session-name new file mode 100755 index 00000000..8cc07efc --- /dev/null +++ b/shell/tmux/bin/tmux-session-name @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +id=$(echo $TMUX | sed 's/.*,//g') +res=$(tmux ls -F '#{session_id}:#{session_name}' | grep -e "^\$$id:") + +[[ $res ]] || exit 1 +echo "${res#\$$id:}"