Skip to content

Commit

Permalink
#298: simplify and use more universal PATH mod export string (#301)
Browse files Browse the repository at this point in the history
* #298: simplify and use more universal PATH mod export string

* #298: simplify and use more universal PATH mod export string part 2

* #298: simplify and use more universal PATH mod export string

* #298: simplify and use more universal PATH mod export string part 2

* #298: simplify and use more universal PATH mod export string part 3
  • Loading branch information
pirog authored Dec 11, 2024
1 parent d4caa93 commit 7f92167
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})

* Simplified `lando shellenv --add` `PATH` modification string to be more universal [#298](https://github.com/lando/core/issues/298)

## v3.23.19 - [December 7, 2024](https://github.com/lando/core/releases/tag/v3.23.19)

* Fixed bug causing auto setup to not correctly reset the orchestrator binary path
Expand All @@ -21,7 +23,7 @@
## v3.23.15 - [December 3, 2024](https://github.com/lando/core/releases/tag/v3.23.15)

* Disabled `DOCKER_CLI_HINTS` on `lando`
* Fixed bug causing some `lando exec` and tooling commands from not inheriting terminal columns and lines correctly[#277](https://github.com/lando/core/issues/277)
* Fixed bug causing some `lando exec` and tooling commands from not inheriting terminal columns and lines correctly [#277](https://github.com/lando/core/issues/277)
* Fixed bug causing `lando setup` loop on `U Need Setup!`
* Fixed bug causing failed update message when user needs to relaunch terminal
* Improved `ux` for `autosetup`
Expand Down
2 changes: 1 addition & 1 deletion examples/certs/.lando.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ services:
- 8080/http
curl:
api: 4
image: curlimages/curl
image: curlimages/curl:8.10.1
command: sleep infinity

tooling:
Expand Down
3 changes: 1 addition & 2 deletions utils/get-shellenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ module.exports = (paths = [], shell = require('./get-user-shell')()) => {

default:
return [
['# Lando'],
[`export PATH="${paths}\${PATH+:$PATH}"; #landopath`, '#landopath'],
[`export PATH="${paths}:$PATH"; #landopath`, '#landopath'],
];
}
};
18 changes: 8 additions & 10 deletions utils/update-shell-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const os = require('os');
const read = require('./read-file');
const write = require('./write-file');

const trim = (data = []) => {
while (data.length > 0 && data[data.length - 1] === '') data.pop();
data.push('');
return data;
};

module.exports = (file, updates = []) => {
// create empty file if it doesnt exist first
if (!fs.existsSync(file)) {
Expand All @@ -17,12 +23,7 @@ module.exports = (file, updates = []) => {
// get the content
const content = read(file);
// split into lines
const lines = content.split('\n');
// get penulimatimate
const penny = Math.max(lines.length - 2, 0);

// if we end up with second to last line that is empty then pop
if (penny > 0 && lines[lines.length - 2].trim() === '') lines.pop();
const lines = trim(content.split('\n'));

// loops through the updates and add/update as needed
for (const [update, search] of updates) {
Expand All @@ -34,11 +35,8 @@ module.exports = (file, updates = []) => {
}
}

// if the last element doesnt contain a newline
if (!lines[lines.length - 1].includes(os.EOL)) lines.push(os.EOL);

// Write the modified content back to the file
write(file, lines.join(os.EOL));
write(file, `${trim(lines).join(os.EOL)}${os.EOL}`);

// handle errors
} catch (error) {
Expand Down

0 comments on commit 7f92167

Please sign in to comment.