path_utils 0.0.1
path_utils: ^0.0.1 copied to clipboard
Cross-platform path resolution and subprocess environment utilities. Resolves GUI-app PATH gaps, finds executables, and runs commands with a shell-aware environment.
path_utils #
Cross-platform path resolution and subprocess environment utilities.
GUI-launched apps on macOS and Linux often inherit a minimal PATH. This package
merges the process environment with the user's interactive shell (and common
fallback directories), then uses that environment to find executables and run
commands.
Install #
dependencies:
path_utils: ^0.0.1
Usage #
import 'package:path_utils/path_utils.dart';
Future<void> main() async {
final home = PlatformPaths.expandUser('~/projects');
final shell = ShellEnvironment();
final pathDirs = await shell.getComprehensivePathDirs();
final finder = ExecutableFinder(onDebugLog: (msg, {context}) {});
final git = await finder.find('git');
final executor = CommandExecutor(
onExecutionLog: (msg, {context}) {},
onDebugLog: (msg, {context}) {},
showMessage: (msg, severity) {},
executableFinder: finder,
shellEnvironment: shell,
);
final result = await executor.runGenericCommand(
'echo',
['hello'],
workingDirectory: home,
);
print(result.output); // hello
print(pathDirs.take(3).toList());
print(git);
}
What it provides #
Paths (PlatformPaths, ShellEnvironment) #
ShellEnvironment merges:
- the inherited process environment
- values from the user's interactive shell (when not running under
FLUTTER_TEST) - common fallback directories (
/usr/local/bin,/opt/homebrew/bin, etc.)
PlatformPaths provides cross-platform helpers for home-directory expansion
(~/), PATH list parsing, normalization, and POSIX shell quoting.
Command execution (CommandExecutor, ExecutableFinder) #
Finds executables on the comprehensive PATH and runs subprocesses with the
resolved environment (including optional JAVA_HOME on Unix).
Example app #
A Flutter demo lives in example/:
cd example
flutter pub get
flutter run -d linux # or macos / windows
Testing #
dart pub get
dart test
License #
MIT — see LICENSE.