From 7e74a329f938a1863dabee543ce567b5b6b0fef5 Mon Sep 17 00:00:00 2001 From: Adi Date: Thu, 28 Jan 2021 22:42:36 +0530 Subject: [PATCH] v1.0.0 initial release --- .gitignore | 9 ++ CHANGELOG.md | 22 +++++ pia.tmux | 51 +++++++++++ scripts/flag.sh | 224 +++++++++++++++++++++++++++++++++++++++++++++ scripts/helpers.sh | 18 ++++ scripts/ip.sh | 18 ++++ scripts/port.sh | 24 +++++ scripts/region.sh | 224 +++++++++++++++++++++++++++++++++++++++++++++ scripts/status.sh | 45 +++++++++ 9 files changed, 635 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100755 pia.tmux create mode 100755 scripts/flag.sh create mode 100755 scripts/helpers.sh create mode 100755 scripts/ip.sh create mode 100755 scripts/port.sh create mode 100755 scripts/region.sh create mode 100755 scripts/status.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8bfaac4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d6691e0 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,22 @@ +

Changelog

+

+

+ Status + License +

+ +### Index +* [v 1.0.0](#v1.0.0) +* [Versioning System](#versioning-system) +* [License](#license) + +#### v1.0.0 +_28/01/2021_ +- Initial Release + +#### Versioning System +PIA-Tmux uses [Semantic versioning 2.0.0](https://semver.org) + +#### License +[MIT](https://github.com/Brutuski/tmux-piavpn/blob/main/LICENSE) +_Copyright (c) 2021 Adhiraj Sirohi_ \ No newline at end of file diff --git a/pia.tmux b/pia.tmux new file mode 100755 index 0000000..07ffa32 --- /dev/null +++ b/pia.tmux @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$CURRENT_DIR/scripts/helpers.sh" + +pia_commands=( + "#($CURRENT_DIR/scripts/status.sh)" + "#($CURRENT_DIR/scripts/ip.sh)" + "#($CURRENT_DIR/scripts/region.sh)" + "#($CURRENT_DIR/scripts/flag.sh)" + "#($CURRENT_DIR/scripts/port.sh)" +) + +pia_interpolation=( + "\#{pia_status}" + "\#{pia_ip}" + "\#{pia_region}" + "\#{pia_flag}" + "\#{pia_port}" +) + +set_tmux_options() { + local option="$1" + local value="$2" + tmux set-option -gp "$option" "$value" +} + +do_interpolation() { + local interpolated="$1" + + for ((i=0; i<${#pia_commands[@]}; i++)); do + interpolated=${interpolated/${pia_interpolation[$i]}/${pia_commands[$i]}} + done + + echo "$interpolated" +} + +update_tmux_option() { + local option="$1" + local option_value="$(get_tmux_option "$option")" + local new_option_value="$(do_interpolation "$option_value")" + set_tmux_option "$option" "$new_option_value" +} + +main() { + update_tmux_option "status-right" + update_tmux_option "status-left" +} + +main + diff --git a/scripts/flag.sh b/scripts/flag.sh new file mode 100755 index 0000000..6b2ac3f --- /dev/null +++ b/scripts/flag.sh @@ -0,0 +1,224 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$CURRENT_DIR/helpers.sh" + +state=$(piactl get connectionstate) + +main () { + if [ $state == "Connected" ]; then + get_region + else + printf "" + fi +} + +get_region() +{ + region=$(piactl get region) + + if [ $region == "albania" ]; then + printf "🇦" + elif [ $region == "algeria" ]; then + printf "🇩🇿" + elif [ $region == "andorra" ]; then + printf "🇦🇩" + elif [ $region == "argentina" ]; then + printf "🇦🇩" + elif [ $region == "armenia" ]; then + printf "🇦🇲" + elif [ $region == "au-melbourne" ]; then + printf "🇦🇺" + elif [ $region == "au-perth" ]; then + printf "🇦🇺" + elif [ $region == "au-sydney" ]; then + printf "🇦🇺" + elif [ $region == "austria" ]; then + printf "🇦🇹" + elif [ $region == "bahamas" ]; then + printf "🇧🇸" + elif [ $region == "bangladesh" ]; then + printf "🇧🇩" + elif [ $region == "belgium" ]; then + printf "🇧🇪" + elif [ $region == "bosnia-and-herzegovina" ]; then + printf "🇧🇦" + elif [ $region == "brazil" ]; then + printf "🇧🇷" + elif [ $region == "bulgaria" ]; then + printf "🇧🇬" + elif [ $region == "ca-montreal" ]; then + printf "🇨🇦" + elif [ $region == "ca-ontario" ]; then + printf "🇨🇦" + elif [ $region == "ca-toronto" ]; then + printf "🇨🇦" + elif [ $region == "ca-vancouver" ]; then + printf "🇨🇦" + elif [ $region == "cambodia" ]; then + printf "🇰🇭" + elif [ $region == "china" ]; then + printf "🇨🇳" + elif [ $region == "cyprus" ]; then + printf "🇨🇾" + elif [ $region == "czech-republic" ]; then + printf "🇨🇿" + elif [ $region == "de-berlin" ]; then + printf "🇩🇪" + elif [ $region == "de-frankfurt" ]; then + printf "🇩🇪" + elif [ $region == "denmark" ]; then + printf "🇩🇰" + elif [ $region == "egypt" ]; then + printf "🇪🇬" + elif [ $region == "estonia" ]; then + printf "🇪🇪" + elif [ $region == "finland" ]; then + printf "🇫🇮" + elif [ $region == "france" ]; then + printf "🇫🇷" + elif [ $region == "georgia" ]; then + printf "🇬🇪" + elif [ $region == "greece" ]; then + printf "🇬🇷" + elif [ $region == "greenland" ]; then + printf "🇬🇱" + elif [ $region == "hong-kong" ]; then + printf "🇭🇰" + elif [ $region == "hungary" ]; then + printf "🇭🇺" + elif [ $region == "iceland" ]; then + printf "🇮🇸" + elif [ $region == "india" ]; then + printf "🇮🇳" + elif [ $region == "ireland" ]; then + printf "🇮🇪" + elif [ $region == "isle-of-man" ]; then + printf "🇮🇲" + elif [ $region == "israel" ]; then + printf "🇮🇱" + elif [ $region == "italy" ]; then + printf "🇮🇹" + elif [ $region == "japan" ]; then + printf "🇯🇵" + elif [ $region == "kazakhstan" ]; then + printf "🇰🇿" + elif [ $region == "latvia" ]; then + printf "🇱🇻" + elif [ $region == "liechtenstein" ]; then + printf "🇱🇮" + elif [ $region == "lithuania" ]; then + printf "🇱🇹" + elif [ $region == "luxembourg" ]; then + printf "🇱🇺" + elif [ $region == "macao" ]; then + printf "🇲🇴" + elif [ $region == "macedonia" ]; then + printf "🇲🇰" + elif [ $region == "malta" ]; then + printf "🇲🇹" + elif [ $region == "mexico" ]; then + printf "🇲🇽" + elif [ $region == "moldova" ]; then + printf "🇲🇩" + elif [ $region == "monaco" ]; then + printf "🇲🇨" + elif [ $region == "mongolia" ]; then + printf "🇲🇳" + elif [ $region == "montenegro" ]; then + printf "🇲🇪" + elif [ $region == "morocco" ]; then + printf "🇲🇦" + elif [ $region == "netherlands" ]; then + printf "🇳🇱" + elif [ $region == "new-zealand" ]; then + printf "🇳🇿" + elif [ $region == "nigeria" ]; then + printf "🇳🇬" + elif [ $region == "norway" ]; then + printf "🇳🇴" + elif [ $region == "panama" ]; then + printf "🇵🇦" + elif [ $region == "philippines" ]; then + printf "🇵🇭" + elif [ $region == "poland" ]; then + printf "🇵🇱" + elif [ $region == "portugal" ]; then + printf "🇵🇹" + elif [ $region == "qatar" ]; then + printf "🇶🇦" + elif [ $region == "romania" ]; then + printf "🇷🇴" + elif [ $region == "saudi-arabia" ]; then + printf "🇸🇦" + elif [ $region == "serbia" ]; then + printf "🇷🇸" + elif [ $region == "singapore" ]; then + printf "🇸🇬" + elif [ $region == "slovakia" ]; then + printf "🇸🇰" + elif [ $region == "south-africa" ]; then + printf "🇿🇦" + elif [ $region == "spain" ]; then + printf "🇪🇸" + elif [ $region == "sri-lanka" ]; then + printf "🇱🇰" + elif [ $region == "sweden" ]; then + printf "🇸🇪" + elif [ $region == "switzerland" ]; then + printf "🇨🇭" + elif [ $region == "taiwan" ]; then + printf "🇹🇼" + elif [ $region == "turkey" ]; then + printf "🇹🇷" + elif [ $region == "uk-london" ]; then + printf "🇬🇧" + elif [ $region == "uk-london---streaming-optimized" ]; then + printf "🇬🇧" + elif [ $region == "uk-manchester" ]; then + printf "🇬🇧" + elif [ $region == "uk-southampton" ]; then + printf "🇬🇧" + elif [ $region == "ukraine" ]; then + printf "🇺🇦" + elif [ $region == "united-arab-emirates" ]; then + printf "🇦🇪" + elif [ $region == "us-atlanta" ]; then + printf "🇺🇸" + elif [ $region == "us-california" ]; then + printf "🇺🇸" + elif [ $region == "us-chicago" ]; then + printf "🇺🇸" + elif [ $region == "us-denver" ]; then + printf "🇺🇸" + elif [ $region == "us-east" ]; then + printf "🇺🇸" + elif [ $region == "us-florida" ]; then + printf "🇺🇸" + elif [ $region == "us-houston" ]; then + printf "🇺🇸" + elif [ $region == "us-las-vegas" ]; then + printf "🇺🇸" + elif [ $region == "us-new-york" ]; then + printf "🇺🇸" + elif [ $region == "us-seattle" ]; then + printf "🇺🇸" + elif [ $region == "us-silicon-valley" ]; then + printf "🇺🇸" + elif [ $region == "us-texas" ]; then + printf "🇺🇸" + elif [ $region == "us-washington-dc" ]; then + printf "🇺🇸" + elif [ $region == "us-west" ]; then + printf "🇺🇸" + elif [ $region == "venezuela" ]; then + printf "🇻🇪" + elif [ $region == "vietnam" ]; then + printf "🇻🇳" + else + printf "" + fi +} + +main + diff --git a/scripts/helpers.sh b/scripts/helpers.sh new file mode 100755 index 0000000..353a352 --- /dev/null +++ b/scripts/helpers.sh @@ -0,0 +1,18 @@ +get_tmux_option() { + local option=$1 + local default_value=$2 + local option_value="$(tmux show-option -gqv "$option")" + + if [[ -z "option_value" ]]; then + echo "$default_value" + else + echo "$option_value" + fi +} + +set_tmux_option() { + local option=$1 + local value=$2 + tmux set-option -gq "$option" "$value" +} + diff --git a/scripts/ip.sh b/scripts/ip.sh new file mode 100755 index 0000000..24ed69f --- /dev/null +++ b/scripts/ip.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$CURRENT_DIR/helpers.sh" + +get_ip() +{ + ip=$(piactl get vpnip) + + if [[ $ip == "Unknown" ]]; then + printf "" + else + printf "$ip" + fi +} + +get_ip + diff --git a/scripts/port.sh b/scripts/port.sh new file mode 100755 index 0000000..21e9433 --- /dev/null +++ b/scripts/port.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$CURRENT_DIR/helpers.sh" + +get_port() +{ + port=$(piactl get portforward) + + if [[ $port == "Inactive" ]]; then + printf "Inactive" + elif [[ $port == "Attempting" ]]; then + printf "Port Attempting..." + elif [[ $port == "Failed" ]]; then + printf "Port Failed" + elif [[ $port == "Unavailable" ]]; then + printf "Port Unavailable" + else + printf "$port" + fi +} + +get_port + diff --git a/scripts/region.sh b/scripts/region.sh new file mode 100755 index 0000000..8d7aae4 --- /dev/null +++ b/scripts/region.sh @@ -0,0 +1,224 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$CURRENT_DIR/helpers.sh" + +state=$(piactl get connectionstate) + +main () { + if [ $state == "Connected" ]; then + get_region + else + printf "" + fi +} + +get_region() +{ + region=$(piactl get region) + + if [ $region == "albania" ]; then + printf "to Albania" + elif [ $region == "algeria" ]; then + printf "to Algeria" + elif [ $region == "andorra" ]; then + printf "to Andorra" + elif [ $region == "argentina" ]; then + printf "to Argentina" + elif [ $region == "armenia" ]; then + printf "to Armenia" + elif [ $region == "au-melbourne" ]; then + printf "to Australia" + elif [ $region == "au-perth" ]; then + printf "to Australia" + elif [ $region == "au-sydney" ]; then + printf "to Australia" + elif [ $region == "austria" ]; then + printf "to Austria" + elif [ $region == "bahamas" ]; then + printf "to Bahamas" + elif [ $region == "bangladesh" ]; then + printf "to Bangladesh" + elif [ $region == "belgium" ]; then + printf "to Belgium" + elif [ $region == "bosnia-and-herzegovina" ]; then + printf "to Bosnia and Herzogovina" + elif [ $region == "brazil" ]; then + printf "to Brazil" + elif [ $region == "bulgaria" ]; then + printf "to Bulgaria" + elif [ $region == "ca-montreal" ]; then + printf "to Canada" + elif [ $region == "ca-ontario" ]; then + printf "to Canada" + elif [ $region == "ca-toronto" ]; then + printf "to Canada" + elif [ $region == "ca-vancouver" ]; then + printf "to Canada" + elif [ $region == "cambodia" ]; then + printf "to Cambodia" + elif [ $region == "china" ]; then + printf "to China" + elif [ $region == "cyprus" ]; then + printf "to Cyprus" + elif [ $region == "czech-republic" ]; then + printf "to Czech Republic" + elif [ $region == "de-berlin" ]; then + printf "to Germany" + elif [ $region == "de-frankfurt" ]; then + printf "to Germany" + elif [ $region == "denmark" ]; then + printf "to Denmark" + elif [ $region == "egypt" ]; then + printf "to Egypt" + elif [ $region == "estonia" ]; then + printf "to Estonia" + elif [ $region == "finland" ]; then + printf "to Finland" + elif [ $region == "france" ]; then + printf "to France" + elif [ $region == "georgia" ]; then + printf "to Georgia" + elif [ $region == "greece" ]; then + printf "to Greece" + elif [ $region == "greenland" ]; then + printf "to Greenland" + elif [ $region == "hong-kong" ]; then + printf "to Hong Kong" + elif [ $region == "hungary" ]; then + printf "to Hungary" + elif [ $region == "iceland" ]; then + printf "to Iceland" + elif [ $region == "india" ]; then + printf "to India" + elif [ $region == "ireland" ]; then + printf "to Ireland" + elif [ $region == "isle-of-man" ]; then + printf "to Isle of Man" + elif [ $region == "israel" ]; then + printf "to Israel" + elif [ $region == "italy" ]; then + printf "to Italy" + elif [ $region == "japan" ]; then + printf "to Japan" + elif [ $region == "kazakhstan" ]; then + printf "to Kazakhstan" + elif [ $region == "latvia" ]; then + printf "to Latvia" + elif [ $region == "liechtenstein" ]; then + printf "to Lichtenstein" + elif [ $region == "lithuania" ]; then + printf "to Lithuania" + elif [ $region == "luxembourg" ]; then + printf "to Luxembourg" + elif [ $region == "macao" ]; then + printf "to Macao" + elif [ $region == "macedonia" ]; then + printf "to Macedonia" + elif [ $region == "malta" ]; then + printf "to Malta" + elif [ $region == "mexico" ]; then + printf "to Mexico" + elif [ $region == "moldova" ]; then + printf "to Moldova" + elif [ $region == "monaco" ]; then + printf "to Monaco" + elif [ $region == "mongolia" ]; then + printf "to Mongolia" + elif [ $region == "montenegro" ]; then + printf "to Montenegro" + elif [ $region == "morocco" ]; then + printf "to Morocoo" + elif [ $region == "netherlands" ]; then + printf "to MNetherlands" + elif [ $region == "new-zealand" ]; then + printf "to New-Zealand" + elif [ $region == "nigeria" ]; then + printf "to Nigeria" + elif [ $region == "norway" ]; then + printf "to Norway" + elif [ $region == "panama" ]; then + printf "to Panama" + elif [ $region == "philippines" ]; then + printf "to Philippines" + elif [ $region == "poland" ]; then + printf "to Poland" + elif [ $region == "portugal" ]; then + printf "to Portugal" + elif [ $region == "qatar" ]; then + printf "to Qatar" + elif [ $region == "romania" ]; then + printf "to Romania" + elif [ $region == "saudi-arabia" ]; then + printf "to Saudi-Arabia" + elif [ $region == "serbia" ]; then + printf "to Serbia" + elif [ $region == "singapore" ]; then + printf "to Singapore" + elif [ $region == "slovakia" ]; then + printf "to Slovakia" + elif [ $region == "south-africa" ]; then + printf "to South-Africa" + elif [ $region == "spain" ]; then + printf "to Spain" + elif [ $region == "sri-lanka" ]; then + printf "to Sri-Lanka" + elif [ $region == "sweden" ]; then + printf "to Sweden" + elif [ $region == "switzerland" ]; then + printf "to Switzerland" + elif [ $region == "taiwan" ]; then + printf "to Taiwan" + elif [ $region == "turkey" ]; then + printf "to Turkey" + elif [ $region == "uk-london" ]; then + printf "to United Kingdom" + elif [ $region == "uk-london---streaming-optimized" ]; then + printf "to United Kingdom" + elif [ $region == "uk-manchester" ]; then + printf "to United Kingdom" + elif [ $region == "uk-southampton" ]; then + printf "to United Kingdom" + elif [ $region == "ukraine" ]; then + printf "to Ukraine" + elif [ $region == "united-arab-emirates" ]; then + printf "to UAE" + elif [ $region == "us-atlanta" ]; then + printf "to United States" + elif [ $region == "us-california" ]; then + printf "to United States" + elif [ $region == "us-chicago" ]; then + printf "to United States" + elif [ $region == "us-denver" ]; then + printf "to United States" + elif [ $region == "us-east" ]; then + printf "to United States" + elif [ $region == "us-florida" ]; then + printf "to United States" + elif [ $region == "us-houston" ]; then + printf "to United States" + elif [ $region == "us-las-vegas" ]; then + printf "to United States" + elif [ $region == "us-new-york" ]; then + printf "to United States" + elif [ $region == "us-seattle" ]; then + printf "to United States" + elif [ $region == "us-silicon-valley" ]; then + printf "to United States" + elif [ $region == "us-texas" ]; then + printf "to United States" + elif [ $region == "us-washington-dc" ]; then + printf "to United States" + elif [ $region == "us-west" ]; then + printf "to United States" + elif [ $region == "venezuela" ]; then + printf "to Venezuela" + elif [ $region == "vietnam" ]; then + printf "to Vietnam" + else + printf "" + fi +} + +main + diff --git a/scripts/status.sh b/scripts/status.sh new file mode 100755 index 0000000..432e5db --- /dev/null +++ b/scripts/status.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$CURRENT_DIR/helpers.sh" + +text_connected=$(get_tmux_option "@piavpn_text_connected" "Connected") +text_connecting=$(get_tmux_option "@piavpn_text_connecting" "Connecting...") + +text_disconnected=$(get_tmux_option "@piavpn_text_disconnected" "Disconnected") +text_disconnecting=$(get_tmux_option "@piavpn_text_disconnecting" "Disconnecting...") + +text_interrupted=$(get_tmux_option "@piavpn_text_interrupted" "Interrupted") + +text_reconnecting=$(get_tmux_option "@piavpn_text_reconnecting" "Reconnecting...") + +text_still_reconnecting=$(get_tmux_option "@piavpn_text_still_reconnecting" "Reconnecting...") + +text_disconnecting_reconnecting=$(get_tmux_option "@piavpn_text_disconnecting_reconnecting" "Connecting again...") +get_status() +{ + status=$(piactl get connectionstate) + + if [[ $status == "Disconnected" ]]; then + printf "$text_disconnected" + elif [[ $status == "Connecting" ]]; then + printf "$text_connecting" + elif [[ $status == "StillConnecting" ]]; then + printf "$text_connecting" + elif [[ $status == "Connected" ]]; then + printf "$text_connected" + elif [[ $status == "Interrupted" ]]; then + printf "$text_interrupted" + elif [[ $status == "Reconnecting" ]]; then + printf "$text_reconnecting" + elif [[ $status == "StillReconnecting" ]]; then + printf "$text_reconnecting" + elif [[ $status == "DisconnectingToReconnect" ]]; then + printf "$text_disconnecting_reconnecting" + elif [[ $status == "Disconnecting" ]]; then + printf "$text_disconnecting" + fi +} + +get_status +