megafile

package module
v1.7.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: BSD-3-Clause Imports: 31 Imported by: 1

README

MegaFile

License CI

File browser, simple shell and image viewer for the terminal, written in Go.

This project can be used as the github.com/xyproto/megafile package, or as a standalone exectuable.

screenshot

(screenshot of the previous version, before the project rename)

Building
make
Installation
make install
Commands
  • any filename - edit file with $EDITOR
  • cd, .. or any directory name - change directory
  • ./script.sh - execute a script named script.sh
  • ls or dir list directory (happens automatically, though)
  • q, quit or exit - exit program
Hotkeys

Navigation and Selection

  • ↑/↓/←/→ - navigate and select files
  • Page Up/Down - jump to first/last entry in current column
  • Home or ctrl-a - jump to first file (or start of line when typing)
  • End or ctrl-e - jump to last file (or end of line when typing)

Execution

  • Return - execute selected file, or run typed command
  • Esc - clear selection (first press), exit program (second press)

Text Editing

  • Backspace - delete character, or go up directory (when at start)
  • ctrl-h - delete character, or toggle hidden files (when at start)
  • ctrl-d - delete character under cursor, or exit program
  • ctrl-k - delete text to the end of the line
  • ctrl-c - clear text, or exit program

File Operations

  • Tab - cycle through files, or tab completion
  • Delete - move selected file to trash (when no text is typed)
  • ctrl-z or ctrl-u - undo last trash move
  • ctrl-r - rename selected file or directory
  • ctrl-f - search for text in files

Directory Navigation

  • ctrl-space - enter the most recent subdirectory
  • ctrl-n - cycle to next directory
  • ctrl-p - cycle to previous directory
  • ctrl-b - go to parent directory
  • ctrl-w - go to the real path (resolve symlinks)

Display

  • ctrl-o - toggle show hidden files
  • ctrl-l - clear screen

External Tools

  • ctrl-t - run tig
  • ctrl-g - run lazygit

Exit

  • ctrl-q - exit program immediately
Runtime dependencies
  • tig
  • lazygit
  • /bin/sh for displaying the uptime on macOS
General info

Documentation

Overview

Package megafile provides functionality for a simple TUI for browsing files and directories

Index

Constants

View Source
const (

	// NoAction - take no action
	NoAction = iota
	// NextFile - go to the next file
	NextFile
	// PreviousFile - go to the previous file
	PreviousFile
	// StopParent - stop the parent process
	StopParent
)

Variables

View Source
var ErrExit = errors.New("exit")

ErrExit is the error that is returned if the user appeared to want to exit

Functions

func Cleanup

func Cleanup(c *vt.Canvas)

Cleanup tries to set everything right in the terminal emulator before returning

func SetupResizeSignal added in v1.3.14

func SetupResizeSignal(sigChan chan os.Signal)

SetupResizeSignal sets up window resize signal handling (Unix implementation)

func UpsieString added in v1.4.3

func UpsieString(fullKernelVersion bool) (string, error)

UpsieString returns a string describing the hostname, kernel/os, and platform. Colors are used unless NO_COLOR=1 is set.

Types

type Action added in v1.3.5

type Action int

Action is an "enum" for Orbiton to request an action via stderr

type FileEntry added in v1.2.0

type FileEntry struct {
	// contains filtered or unexported fields
}

FileEntry represents a file entry with position and name information

type State

type State struct {
	Header string // title/header

	Directories []string

	AngleColor              vt.AttributeColor
	PromptColor             vt.AttributeColor
	HeaderColor             vt.AttributeColor
	HighlightForeground     vt.AttributeColor
	HighlightBackground     vt.AttributeColor
	Background              vt.AttributeColor
	EdgeBackground          vt.AttributeColor
	WrittenTextColor        vt.AttributeColor
	SymlinkDirColor         vt.AttributeColor
	DirColor                vt.AttributeColor
	SymlinkFileColor        vt.AttributeColor
	EmptyFileColor          vt.AttributeColor
	ExecutableColor         vt.AttributeColor
	BinaryColor             vt.AttributeColor
	FileColor               vt.AttributeColor
	BinaryConfirmForeground vt.AttributeColor
	BinaryConfirmBackground vt.AttributeColor
	SyntaxTextConfig        *synhi.TextConfig // theme colors for syntax highlighting in previews
	Light                   bool              // true if the theme has a light background

	ShowHidden bool
	// contains filtered or unexported fields
}

State holds the current state of the shell, then canvas and the directory structures

func New added in v1.2.7

func New(c *vt.Canvas, tty *vt.TTY, startdirs []string, header, editor, undoHistoryPath string) *State

New creates a new MegaFile State c and tty is a canvas and TTY, initiated with the vt package startdirs is a slice of directories to browse (toggle with tab) header is the string to display at the top of the screen the function returns the absolute path to the directory the user ended up in, and an error if something went wrong

func (*State) FullResetRedraw added in v1.3.14

func (s *State) FullResetRedraw()

FullResetRedraw will completely reset and redraw everything, including creating a brand new Canvas struct. Only redraws when in file browsing mode, not when an external editor/command is running.

func (*State) RealPath added in v1.3.14

func (s *State) RealPath() bool

RealPath checks if the current path is the same if symlinks are not followed (pwd -P) (the "real" path)

func (*State) ResetTerminal added in v1.6.19

func (s *State) ResetTerminal()

ResetTerminal resets the VT terminal and creates a fresh canvas, without redrawing any content. Use this when the screen will be immediately taken over by another external command.

func (*State) Run added in v1.2.7

func (s *State) Run() ([]string, error)

Run launches a file browser and returns the currently selected directories when it is done running

Directories

Path Synopsis
cmd
megafile command
package main is the main package for the MegaFile program
package main is the main package for the MegaFile program

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL