Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File paths on MacOS with ~ is not recognized as HOME #173

Closed
alexgwalley opened this issue Mar 3, 2023 · 5 comments
Closed

File paths on MacOS with ~ is not recognized as HOME #173

alexgwalley opened this issue Mar 3, 2023 · 5 comments

Comments

@alexgwalley
Copy link

When using ols.json to specify core and vendor library locations, I found that ols does not recognize the ~ as the HOME environment variable and [LS] autocomplete ceased to work.

I am using Neo-Vim and CoC.

I think that on MacOS ols should do a string replace for ~ with HOME.

@DanielGavin
Copy link
Owner

It already does.

It works fine for Linux, so someone with a MacOS has to figure out why this doesn't work:

home := os.get_env("HOME", context.temp_allocator)
strings.replace(forward_path, "~", home, 1, context.temp_allocator)

@wiremoons
Copy link

Hi @DanielGavin

Thought I would try to help with this bug report as I use Odin and macOS.

I tested the above suggested code on macOS and found the code suggested does not work as expected. It does not work on Linux (Ubuntu 22.04.2 LTS on Raspberry Pi) either.

The example output from the test code below on both macOS and Linux is:

% odin run dir_test.odin -file

example path: '~/.Odin'
checking 'forward_path[0]': '126' [~]
env HOME is: '/Users/simon'
Orignal OLS code - updated 'forward_path' is: '~/.Odin'
New code - updated 'forward_path' is: '/Users/simon/.Odin'

Example code used to test:

// run with:  odin run dir_test.odin -file
package main

import "core:fmt"
import "core:strings"
import "core:os"

main :: proc() {
    // create an example path to test in macOS
    forward_path : string = "~/.Odin"
    fmt.printf("\nexample path: '%s'\n",forward_path)
    // Lines below extract from: ols/src/server/requests.odin lines 515-530
    // with additional 'fmt.printf' statements added.
    //
    //Support a basic use of '~'
    when ODIN_OS != .Windows {
        fmt.printf("checking 'forward_path[0]': '%v' [%c]\n",forward_path[0],i32(forward_path[0]))
        if forward_path[0] == '~' {
            home := os.get_env(
                "HOME",
                context.temp_allocator,
            )
            fmt.printf("env HOME is: '%s'\n",home)
            strings.replace(
                forward_path,
                "~",
                home,
                1,
                context.temp_allocator,
            )
            fmt.printf("Orignal OLS code - updated 'forward_path' is: '%s'\n",forward_path)
            //
            // new code below - capture the 'replace' proc returned value
            forward_path, _ := strings.replace(
                forward_path,
                "~",
                home,
                1,
                context.temp_allocator,
            )
            fmt.printf("New code - updated 'forward_path' is: '%s'\n",forward_path)
        }
    }
}

Odin version used:

Odin: dev-2023-06:d97dd99d
OS:   macOS Unknown (build: 22F66, kernel: 22.5.0)
CPU:  ARM64
RAM:  8192 MiB

Odin: dev-2023-06:4c17e2e9
OS:   Ubuntu 22.04.2 LTS, Linux 5.15.0-1029-raspi
CPU:  ARM64
RAM:  7807 MiB

I could not see how to find the OLS version being used - but the last update made was:

commit 6b8e30e7ce91d24389a7ed20a6958f5272b10bfb (HEAD -> master, origin/master, origin/HEAD)
error: cannot run gpg: No such file or directory
Author: DanielGavin <danielgavin5@hotmail.com>
Date:   Mon Jun 12 13:33:06 2023 +0200

    Update README.md

Do you want me to create a PR with the above change to fix the use of strings.replace or would you rather look at it yourself?

Hope that helps :)

Simon

@DanielGavin
Copy link
Owner

Thanks Simon.

I can make the small change. Yeah I forgot to assign after the replace.

@DanielGavin
Copy link
Owner

The code has been pushed.

@wiremoons
Copy link

That's great @DanielGavin - glad it was useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants