Skip to main content
edited body
Source Link
Brad Parks
  • 1.8k
  • 3
  • 22
  • 41

While not a tmux solution, add the following to your ~/.zshrc, and it will switch to the relative folder formfrom /etc/synthetic.conf when your shell loads

# find parent folder from /etc/synthetic.conf
switch_to_synth_root() {
    local FILE="/etc/synthetic.conf"
    local curr_dir="$PWD"

    # Check if /etc/synthetic.conf exists
    if [[ ! -f "$FILE" ]]; then
        return 0
    fi

    # processead the synthetic.conf file
    while IFS=$'\t' read -r synthetic_path real_path; do
        # Skip empty lines
        [[ -z "$synthetic_path" || "$synthetic_path" == \#* ]] && continue

        # Check if the current folder is a subdir of the mapped path
        if [[ "$curr_dir" == "$real_path"* ]]; then
            # Ensure that the target folder exists before switching there
            target_path="/${curr_dir//$real_path/$synthetic_path}"
            if [[ -d "$target_path" ]]; then
                cd "$target_path"
            fi
            return 0
        fi
    done < "$FILE"
}

switch_to_synth_root

While not a tmux solution, add the following to your ~/.zshrc, and it will switch to the relative folder form /etc/synthetic.conf when your shell loads

# find parent folder from /etc/synthetic.conf
switch_to_synth_root() {
    local FILE="/etc/synthetic.conf"
    local curr_dir="$PWD"

    # Check if /etc/synthetic.conf exists
    if [[ ! -f "$FILE" ]]; then
        return 0
    fi

    # processead the synthetic.conf file
    while IFS=$'\t' read -r synthetic_path real_path; do
        # Skip empty lines
        [[ -z "$synthetic_path" || "$synthetic_path" == \#* ]] && continue

        # Check if the current folder is a subdir of the mapped path
        if [[ "$curr_dir" == "$real_path"* ]]; then
            # Ensure that the target folder exists before switching there
            target_path="/${curr_dir//$real_path/$synthetic_path}"
            if [[ -d "$target_path" ]]; then
                cd "$target_path"
            fi
            return 0
        fi
    done < "$FILE"
}

switch_to_synth_root

While not a tmux solution, add the following to your ~/.zshrc, and it will switch to the relative folder from /etc/synthetic.conf when your shell loads

# find parent folder from /etc/synthetic.conf
switch_to_synth_root() {
    local FILE="/etc/synthetic.conf"
    local curr_dir="$PWD"

    # Check if /etc/synthetic.conf exists
    if [[ ! -f "$FILE" ]]; then
        return 0
    fi

    # processead the synthetic.conf file
    while IFS=$'\t' read -r synthetic_path real_path; do
        # Skip empty lines
        [[ -z "$synthetic_path" || "$synthetic_path" == \#* ]] && continue

        # Check if the current folder is a subdir of the mapped path
        if [[ "$curr_dir" == "$real_path"* ]]; then
            # Ensure that the target folder exists before switching there
            target_path="/${curr_dir//$real_path/$synthetic_path}"
            if [[ -d "$target_path" ]]; then
                cd "$target_path"
            fi
            return 0
        fi
    done < "$FILE"
}

switch_to_synth_root
Source Link
Brad Parks
  • 1.8k
  • 3
  • 22
  • 41

While not a tmux solution, add the following to your ~/.zshrc, and it will switch to the relative folder form /etc/synthetic.conf when your shell loads

# find parent folder from /etc/synthetic.conf
switch_to_synth_root() {
    local FILE="/etc/synthetic.conf"
    local curr_dir="$PWD"

    # Check if /etc/synthetic.conf exists
    if [[ ! -f "$FILE" ]]; then
        return 0
    fi

    # processead the synthetic.conf file
    while IFS=$'\t' read -r synthetic_path real_path; do
        # Skip empty lines
        [[ -z "$synthetic_path" || "$synthetic_path" == \#* ]] && continue

        # Check if the current folder is a subdir of the mapped path
        if [[ "$curr_dir" == "$real_path"* ]]; then
            # Ensure that the target folder exists before switching there
            target_path="/${curr_dir//$real_path/$synthetic_path}"
            if [[ -d "$target_path" ]]; then
                cd "$target_path"
            fi
            return 0
        fi
    done < "$FILE"
}

switch_to_synth_root