Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
initial release
  • Loading branch information
Adi authored and Adi committed Jan 28, 2021
1 parent c4b5c5b commit 7e74a32
Show file tree
Hide file tree
Showing 9 changed files with 635 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<h2 align="center"> Changelog</h3>
<p align="center"><img src="https://raw.githubusercontent.com/Brutuski/tmux-piavpn/c4b5c5b8a01e0e81d8bc86bcb76cd72c4490e57c/assets/Logo.svg" width="200" height="200"><p>
<p align="center">
<img alt="Status" src="https://img.shields.io/badge/Maintained-Yes-44B273.svg">
<img alt="License" src="https://img.shields.io/badge/LICENSE-MIT-1D918B.svg">
</p>

### 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_
51 changes: 51 additions & 0 deletions pia.tmux
Original file line number Diff line number Diff line change
@@ -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

224 changes: 224 additions & 0 deletions scripts/flag.sh
Original file line number Diff line number Diff line change
@@ -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

18 changes: 18 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
@@ -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"
}

18 changes: 18 additions & 0 deletions scripts/ip.sh
Original file line number Diff line number Diff line change
@@ -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

24 changes: 24 additions & 0 deletions scripts/port.sh
Original file line number Diff line number Diff line change
@@ -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

Loading

0 comments on commit 7e74a32

Please sign in to comment.