utils.sh
1 #!/usr/bin/env bash 2 3 # ------------------------------------------------------------------------------ 4 5 get_tmux_option() { 6 local option=$1 7 local default_value=$2 8 local option_value 9 option_value=$(tmux show-option -gqv "$option") 10 11 if [[ -z "$option_value" ]]; then 12 echo "$default_value" 13 else 14 echo "$option_value" 15 fi 16 } 17 18 display_message() { 19 tmux display-message "tmux-pass: $1" 20 } 21 22 is_cmd_exists() { 23 command -v "$1" &>/dev/null 24 return $? 25 } 26 27 copy_to_clipboard() { 28 if [[ "$(uname)" == "Darwin" ]] && is_cmd_exists "pbcopy"; then 29 echo -n "$1" | pbcopy 30 elif [[ "$(uname)" == "Linux" ]] && is_cmd_exists "xsel"; then 31 echo -n "$1" | xsel -b 32 elif [[ "$(uname)" == "Linux" ]] && is_cmd_exists "xclip"; then 33 echo -n "$1" | xclip -i 34 else 35 return 1 36 fi 37 } 38 39 clear_clipboard() { 40 local -r SEC="$1" 41 42 if [[ "$(uname)" == "Darwin" ]] && is_cmd_exists "pbcopy"; then 43 tmux run-shell -b "sleep $SEC && echo '' | pbcopy" 44 elif [[ "$(uname)" == "Linux" ]] && is_cmd_exists "xsel"; then 45 tmux run-shell -b "sleep $SEC && xsel -c -b" 46 elif [[ "$(uname)" == "Linux" ]] && is_cmd_exists "xclip"; then 47 tmux run-shell -b "sleep $SEC && echo '' | xclip -i" 48 else 49 return 1 50 fi 51 }