-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_functions
40 lines (36 loc) · 1.39 KB
/
dot_functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ~/.functions
# =============================================================================
# Shell functions sourced by `~/.bashrc` and `~/.zshrc`.
switch_path() {
# Définition des chemins de base
local WSL_BASE="$HOME/dev"
local WIN_BASE="/mnt/n/Dev"
local current_path="$PWD"
# Vérifier si le chemin actuel est sous Windows (/mnt/...)
if [[ "$current_path" == "/mnt/"* ]]; then
# Convertir le chemin Windows en chemin WSL
local relative_path="${current_path#$WIN_BASE}"
local new_path="$WSL_BASE$relative_path"
if [ -d "$new_path" ]; then
cd "$new_path"
echo "🐧 Switched to WSL path: $new_path"
else
echo "❌ Equivalent WSL path not found: $new_path"
fi
# Vérifier si le chemin actuel est sous WSL (~/dev)
elif [[ "$current_path" == "$WSL_BASE"* ]]; then
# Convertir le chemin WSL en chemin Windows
local relative_path="${current_path#$WSL_BASE}"
local new_path="$WIN_BASE$relative_path"
if [ -d "$new_path" ]; then
cd "$new_path"
echo " Switched to Windows path: $new_path"
else
echo "❌ Equivalent Windows path not found: $new_path"
fi
else
echo "⚠️ Current path is not in a synced directory"
echo "WSL base: $WSL_BASE"
echo "Windows base: $WIN_BASE"
fi
}