Skip to main content
The glide.path API provides utilities for working with file system paths and constants for important system directories.

Properties

cwd

The current working directory.
const cwd: string = glide.path.cwd
cwd
string
The absolute path to the current working directory.
Example
console.log('Current directory:', glide.path.cwd);
// Output: /home/user/projects/my-app

const proc = await glide.process.spawn('pwd');
const output = await proc.stdout.text();
console.log(output.trim() === glide.path.cwd); // true

home_dir

The user’s home directory.
const home_dir: string = glide.path.home_dir
home_dir
string
The absolute path to the user’s home directory.
Example
console.log('Home directory:', glide.path.home_dir);
// Linux/macOS: /home/username
// Windows: C:\Users\username

// Read a file from home directory
const bashrc = await glide.fs.read(
  `${glide.path.home_dir}/.bashrc`,
  "utf8"
);

// Check if a config directory exists
const configExists = await glide.fs.exists(
  `${glide.path.home_dir}/.config/app`
);

temp_dir

The system’s temporary directory.
const temp_dir: string = glide.path.temp_dir
temp_dir
string
The absolute path to the system’s temporary directory.
Example
console.log('Temp directory:', glide.path.temp_dir);
// Linux: /tmp
// macOS: /var/folders/...
// Windows: C:\Users\username\AppData\Local\Temp

// Create a temporary file
const tempFile = glide.path.join(
  glide.path.temp_dir,
  'glide-temp-' + Date.now() + '.txt'
);
await glide.fs.write(tempFile, 'temporary data');

// Spawn a process in temp directory
const proc = await glide.process.spawn('ls', [], {
  cwd: glide.path.temp_dir
});

profile_dir

The Glide profile directory where configuration and data are stored.
const profile_dir: string = glide.path.profile_dir
profile_dir
string
The absolute path to Glide’s profile directory.
Example
console.log('Profile directory:', glide.path.profile_dir);
// Typical: ~/.glide/profiles/default

// Check profile directory info
const stat = await glide.fs.stat(glide.path.profile_dir);
console.log('Type:', stat.type); // "directory"

// Read a profile-specific file
const configPath = glide.path.join(
  glide.path.profile_dir,
  'glide',
  'glide.ts'
);
const exists = await glide.fs.exists(configPath);

Methods

join()

Join all arguments together and normalize the resulting path.
const path = glide.path.join(
  ...parts: string[]
): string
parts
string[]
required
Path segments to join together.
path
string
The normalized joined path.
Throws an error on non-relative paths. All parts must be relative path segments.
Example: Basic path joining
const path = glide.path.join('/tmp', 'foo', 'bar', 'baz.txt');
console.log(path); // "/tmp/foo/bar/baz.txt"
Example: Build config path
const configPath = glide.path.join(
  glide.path.home_dir,
  '.config',
  'myapp',
  'settings.json'
);
// Linux/macOS: /home/user/.config/myapp/settings.json
Example: Create nested file
const filePath = glide.path.join(
  glide.path.profile_dir,
  'glide',
  'styles',
  'custom.css'
);
await glide.fs.write(filePath, '.button { color: red; }');
Example: Path with environment variable
const dataDir = glide.env.get('XDG_DATA_HOME') ||
  glide.path.join(glide.path.home_dir, '.local', 'share');

const appData = glide.path.join(dataDir, 'myapp', 'data.db');

Usage Patterns

Working with Home Directory

// Expand tilde-like paths
function expandPath(path: string): string {
  if (path.startsWith('~')) {
    return path.replace('~', glide.path.home_dir);
  }
  return path;
}

const expanded = expandPath('~/.config/app');
console.log(expanded); // "/home/user/.config/app"

Platform-Specific Paths

function getConfigDir(): string {
  switch (glide.ctx.os) {
    case 'win':
      const appData = glide.env.get('APPDATA');
      return appData || glide.path.join(glide.path.home_dir, 'AppData', 'Roaming');
    case 'macosx':
      return glide.path.join(glide.path.home_dir, 'Library', 'Application Support');
    default:
      const xdgConfig = glide.env.get('XDG_CONFIG_HOME');
      return xdgConfig || glide.path.join(glide.path.home_dir, '.config');
  }
}

const configDir = getConfigDir();
const appConfig = glide.path.join(configDir, 'myapp', 'config.json');

Creating Directory Structures

// Create a nested directory structure
const projectDir = glide.path.join(
  glide.path.home_dir,
  'projects',
  'myapp'
);

await glide.fs.mkdir(glide.path.join(projectDir, 'src'));
await glide.fs.mkdir(glide.path.join(projectDir, 'dist'));
await glide.fs.mkdir(glide.path.join(projectDir, 'tests'));

// Write files
await glide.fs.write(
  glide.path.join(projectDir, 'src', 'index.ts'),
  'export {}'
);

Temporary File Management

// Create unique temporary file
function createTempFile(prefix: string, extension: string): string {
  const filename = `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2)}${extension}`;
  return glide.path.join(glide.path.temp_dir, filename);
}

const tempLog = createTempFile('glide-log', '.txt');
await glide.fs.write(tempLog, 'Log data...');

// Use temp file with process
const proc = await glide.process.spawn('cat', [tempLog]);
const output = await proc.stdout.text();

Relative vs Absolute Paths

// Check if path is absolute
function isAbsolute(path: string): boolean {
  // Unix-like systems
  if (path.startsWith('/')) return true;
  // Windows
  if (/^[A-Za-z]:\\/.test(path)) return true;
  return false;
}

// Convert relative to absolute
function toAbsolute(path: string, base?: string): string {
  if (isAbsolute(path)) return path;
  return glide.path.join(base || glide.path.cwd, path);
}

const abs = toAbsolute('src/index.ts');
console.log(abs); // "/current/directory/src/index.ts"

Path Constants Reference

PropertyDescriptionExample (Linux/macOS)Example (Windows)
cwdCurrent working directory/home/user/projectC:\Users\user\project
home_dirUser home directory/home/userC:\Users\user
temp_dirSystem temporary directory/tmpC:\Users\user\AppData\Local\Temp
profile_dirGlide profile directory/home/user/.glide/profiles/defaultC:\Users\user\.glide\profiles\default

Path Separators

Glide automatically handles platform-specific path separators:
// Works on all platforms
const path = glide.path.join(
  glide.path.home_dir,
  'Documents',
  'file.txt'
);

// Linux/macOS: /home/user/Documents/file.txt
// Windows: C:\Users\user\Documents\file.txt

Build docs developers (and LLMs) love