aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar@proton.me>2026-04-13 15:56:12 +0530
committerArpit Chakladar <arpitchakladar@proton.me>2026-04-13 15:56:12 +0530
commitf157c61914f9a4da32b4add1920f766dbb66774c (patch)
treec072f5e74dd1205fe2492c9188c5d23e03c5d21d /modules
parente871cd49cca8843b1408be2e7999dba44a370eaf (diff)
downloadhome-manager-config-f157c61914f9a4da32b4add1920f766dbb66774c.tar.gz
home-manager-config-f157c61914f9a4da32b4add1920f766dbb66774c.zip
saving previously selected option for vpn-connect script
Diffstat (limited to 'modules')
-rw-r--r--modules/scripts/vpn-connect.sh40
1 files changed, 32 insertions, 8 deletions
diff --git a/modules/scripts/vpn-connect.sh b/modules/scripts/vpn-connect.sh
index f325e17..87cfdcc 100644
--- a/modules/scripts/vpn-connect.sh
+++ b/modules/scripts/vpn-connect.sh
@@ -2,17 +2,41 @@
CONF_DIR="$HOME/.config/openvpn"
CREDS_DIR="$CONF_DIR/credentials"
SERVERS_DIR="$CONF_DIR/servers"
+CACHE_FILE="$HOME/.cache/openvpn/last_connection"
-# Create directories if they don't exist
-mkdir -p "$CREDS_DIR" "$SERVERS_DIR"
+# Create directories
+mkdir -p "$CREDS_DIR" "$SERVERS_DIR" "$(dirname "$CACHE_FILE")"
-# Select the credential file
-CRED=$(find "$CREDS_DIR" -type f | fzf --prompt="Select Credentials > ")
-[ -z "$CRED" ] && exit 1
+# Logic to force a refresh (bypass cache)
+REFRESH=false
+if [[ "$1" == "--refresh" || "$1" == "-r" ]]; then
+ REFRESH=true
+fi
-# Select the VPN server config
-SERVER=$(find "$SERVERS_DIR" -type f \( -name "*.conf" -o -name "*.ovpn" \) | fzf --prompt="Select VPN Server > ")
-[ -z "$SERVER" ] && exit 1
+# Try to load from cache
+if [[ "$REFRESH" == false && -f "$CACHE_FILE" ]]; then
+ source "$CACHE_FILE"
+ # Validate cached files still exist
+ if [[ ! -f "$CRED" || ! -f "$SERVER" ]]; then
+ echo "Cached config not found, falling back to selection..."
+ REFRESH=true
+ fi
+else
+ REFRESH=true
+fi
+
+# If we need a refresh, run fzf
+if [[ "$REFRESH" == true ]]; then
+ CRED=$(find "$CREDS_DIR" -type f | fzf --prompt="Select Credentials > ")
+ [ -z "$CRED" ] && exit 1
+
+ SERVER=$(find "$SERVERS_DIR" -type f \( -name "*.conf" -o -name "*.ovpn" \) | fzf --prompt="Select VPN Server > ")
+ [ -z "$SERVER" ] && exit 1
+
+ # Save to cache
+ echo "CRED=\"$CRED\"" > "$CACHE_FILE"
+ echo "SERVER=\"$SERVER\"" >> "$CACHE_FILE"
+fi
echo "Connecting to $SERVER using $CRED..."