From 7cc80e8cf4ce1ca3c1f9b06308d4ae5014017ed3 Mon Sep 17 00:00:00 2001 From: Jens Luedicke Date: Mon, 8 Sep 2025 21:16:56 +0200 Subject: [PATCH] Add emacs console helper scripts --- bin/README.md | 126 ++++++++++++++++++++++++++++++++++++++++++++ bin/em | 85 ++++++++++++++++++++++++++++++ bin/emacs-compare | 25 +++++++++ bin/emacs-dev | 19 +++++++ bin/emacs-dired | 17 ++++++ bin/emacs-feeds | 7 +++ bin/emacs-magit | 29 ++++++++++ bin/emacs-mail | 6 +++ bin/emacs-org | 20 +++++++ bin/emacs-portfolio | 6 +++ bin/emacs-quick | 5 ++ bin/emacs-terminal | 22 ++++++++ init.el | 6 +-- lisp/init-core.el | 28 +++++----- 14 files changed, 385 insertions(+), 16 deletions(-) create mode 100644 bin/README.md create mode 100755 bin/em create mode 100755 bin/emacs-compare create mode 100755 bin/emacs-dev create mode 100755 bin/emacs-dired create mode 100755 bin/emacs-feeds create mode 100755 bin/emacs-magit create mode 100755 bin/emacs-mail create mode 100755 bin/emacs-org create mode 100755 bin/emacs-portfolio create mode 100755 bin/emacs-quick create mode 100755 bin/emacs-terminal diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 0000000..330bf8c --- /dev/null +++ b/bin/README.md @@ -0,0 +1,126 @@ +# Emacs Console Helper Scripts + +Collection of helper scripts to launch Emacs in terminal mode (`-nw`) with specific configurations. + +## Installation + +Add this directory to your PATH: + +```bash +export PATH="$HOME/.emacs.d/bin:$PATH" +``` + +Add to your shell configuration file (`~/.bashrc`, `~/.zshrc`, etc.) to make it permanent. + +## Main Launcher + +### `em` - Universal Emacs launcher + +The main entry point for all modes. Usage: + +```bash +em [mode] [args...] +``` + +Without arguments, launches standard Emacs in terminal mode. + +## Available Modes + +### Email +```bash +em mail # Launch mu4e email client +``` + +### RSS Feeds +```bash +em feeds # Launch Elfeed RSS reader +``` + +### Development +```bash +em dev # Launch with development environment +em dev project/ # Open specific project in dev mode +``` + +### Git +```bash +em magit # Launch Magit in current directory +em magit /path/to/repo # Launch Magit in specific repository +``` + +### File Comparison +```bash +em compare file1 file2 # Compare two files using ediff +``` + +### File Manager +```bash +em dired # Launch Dired in current directory +em dired /path/to/dir # Launch Dired in specific directory +``` + +### Portfolio Tracker +```bash +em portfolio # Launch portfolio tracker +``` + +### Org Mode +```bash +em org # Launch Org agenda +em org notes.org # Open/create specific org file +``` + +### Terminal +```bash +em terminal # Launch terminal emulator in Emacs +``` + +### Quick Mode +```bash +em quick # Launch without configuration (emacs -Q) +em quick file.txt # Quick edit without loading config +``` + +## Individual Scripts + +You can also use the scripts directly: + +- `emacs-mail` - Email client +- `emacs-feeds` - RSS reader +- `emacs-dev` - Development environment +- `emacs-magit` - Git interface +- `emacs-compare` - File comparison +- `emacs-dired` - File manager +- `emacs-portfolio` - Portfolio tracker +- `emacs-org` - Org mode +- `emacs-terminal` - Terminal emulator +- `emacs-quick` - Quick mode without config + +## Examples + +```bash +# Quick email check +em mail + +# Work on a project +em dev ~/projects/myapp + +# Compare configuration files +em compare config.old config.new + +# Quick file edit without loading full config +em quick /etc/hosts + +# Manage git repository +em magit ~/projects/myapp + +# Browse files +em dired ~/Documents +``` + +## Tips + +- Use `em quick` for system file edits or when you need fast startup +- The dev mode automatically enables modern development features and Treemacs +- All modes support standard Emacs command-line arguments +- Scripts preserve terminal mode (`-nw`) for console usage \ No newline at end of file diff --git a/bin/em b/bin/em new file mode 100755 index 0000000..b524125 --- /dev/null +++ b/bin/em @@ -0,0 +1,85 @@ +#!/bin/bash +# Main Emacs launcher with mode selection +# Usage: em [mode] [args...] + +SCRIPT_DIR="$(dirname "$0")" + +show_help() { + cat << EOF +Emacs Terminal Mode Launcher + +Usage: em [mode] [args...] + +Available modes: + mail - Launch mu4e email client + feeds - Launch Elfeed RSS reader + dev - Launch development environment with Treemacs + magit - Launch Magit git interface + compare - Compare two files with ediff + dired - Launch Dired file manager + portfolio - Launch portfolio tracker + org - Launch Org mode + terminal - Launch terminal emulator in Emacs + quick - Quick mode without config (emacs -Q) + help - Show this help message + +Without mode argument, launches standard Emacs in terminal. + +Examples: + em # Launch standard Emacs + em mail # Launch email client + em dev myproject/ # Open project in dev mode + em compare f1.txt f2.txt # Compare two files + em magit /path/to/repo # Open Magit in specific repo + +EOF +} + +if [ $# -eq 0 ]; then + # No arguments, launch standard emacs + emacs -nw + exit 0 +fi + +MODE=$1 +shift + +case "$MODE" in + mail) + exec "$SCRIPT_DIR/emacs-mail" "$@" + ;; + feeds) + exec "$SCRIPT_DIR/emacs-feeds" "$@" + ;; + dev) + exec "$SCRIPT_DIR/emacs-dev" "$@" + ;; + magit) + exec "$SCRIPT_DIR/emacs-magit" "$@" + ;; + compare) + exec "$SCRIPT_DIR/emacs-compare" "$@" + ;; + dired) + exec "$SCRIPT_DIR/emacs-dired" "$@" + ;; + portfolio) + exec "$SCRIPT_DIR/emacs-portfolio" "$@" + ;; + org) + exec "$SCRIPT_DIR/emacs-org" "$@" + ;; + terminal) + exec "$SCRIPT_DIR/emacs-terminal" "$@" + ;; + quick) + exec "$SCRIPT_DIR/emacs-quick" "$@" + ;; + help|--help|-h) + show_help + ;; + *) + # Unknown mode, treat as file argument + emacs -nw "$MODE" "$@" + ;; +esac \ No newline at end of file diff --git a/bin/emacs-compare b/bin/emacs-compare new file mode 100755 index 0000000..0937520 --- /dev/null +++ b/bin/emacs-compare @@ -0,0 +1,25 @@ +#!/bin/bash +# Launch Emacs in terminal mode for file comparison (ediff) +# Usage: emacs-compare file1 file2 + +if [ $# -ne 2 ]; then + echo "Usage: $0 file1 file2" + echo "Compare two files using Emacs ediff" + exit 1 +fi + +if [ ! -f "$1" ]; then + echo "Error: File $1 does not exist" + exit 1 +fi + +if [ ! -f "$2" ]; then + echo "Error: File $2 does not exist" + exit 1 +fi + +FILE1=$(realpath "$1") +FILE2=$(realpath "$2") + +EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (ediff-files \"$FILE1\" \"$FILE2\"))" \ No newline at end of file diff --git a/bin/emacs-dev b/bin/emacs-dev new file mode 100755 index 0000000..7e08265 --- /dev/null +++ b/bin/emacs-dev @@ -0,0 +1,19 @@ +#!/bin/bash +# Launch Emacs in terminal mode with development environment +# Accepts optional file/directory argument + +if [ $# -eq 0 ]; then + # No arguments, just start with dev mode + EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (when (fboundp 'enable-dev-mode-modern) + (enable-dev-mode-modern)) + (when (fboundp 'treemacs) + (treemacs)))" +else + # Open specified file/directory + EMACS_NO_DESKTOP=1 emacs -nw "$@" --eval "(progn + (when (fboundp 'enable-dev-mode-modern) + (enable-dev-mode-modern)) + (when (fboundp 'treemacs) + (treemacs)))" +fi \ No newline at end of file diff --git a/bin/emacs-dired b/bin/emacs-dired new file mode 100755 index 0000000..2c64b84 --- /dev/null +++ b/bin/emacs-dired @@ -0,0 +1,17 @@ +#!/bin/bash +# Launch Emacs in terminal mode with Dired file manager +# Accepts optional directory argument + +if [ $# -eq 0 ]; then + # No arguments, use current directory + EMACS_NO_DESKTOP=1 emacs -nw --eval "(dired \".\")" +else + # Use specified directory + if [ -d "$1" ]; then + DIR=$(realpath "$1") + EMACS_NO_DESKTOP=1 emacs -nw --eval "(dired \"$DIR\")" + else + echo "Error: $1 is not a directory" + exit 1 + fi +fi \ No newline at end of file diff --git a/bin/emacs-feeds b/bin/emacs-feeds new file mode 100755 index 0000000..44d5132 --- /dev/null +++ b/bin/emacs-feeds @@ -0,0 +1,7 @@ +#!/bin/bash +# Launch Emacs in terminal mode with Elfeed RSS reader + +EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (require 'elfeed nil t) + (elfeed) + (elfeed-update))" \ No newline at end of file diff --git a/bin/emacs-magit b/bin/emacs-magit new file mode 100755 index 0000000..2294983 --- /dev/null +++ b/bin/emacs-magit @@ -0,0 +1,29 @@ +#!/bin/bash +# Launch Emacs in terminal mode with Magit git interface +# Accepts optional repository path argument + +if [ $# -eq 0 ]; then + # No arguments, use current directory + EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (require 'package) + (package-initialize) + (unless (package-installed-p 'magit) + (package-refresh-contents) + (package-install 'magit)) + (require 'magit) + (magit-status))" +else + # Use specified directory + cd "$1" 2>/dev/null || { + echo "Error: Cannot access directory $1" + exit 1 + } + EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (require 'package) + (package-initialize) + (unless (package-installed-p 'magit) + (package-refresh-contents) + (package-install 'magit)) + (require 'magit) + (magit-status))" +fi \ No newline at end of file diff --git a/bin/emacs-mail b/bin/emacs-mail new file mode 100755 index 0000000..1301991 --- /dev/null +++ b/bin/emacs-mail @@ -0,0 +1,6 @@ +#!/bin/bash +# Launch Emacs in terminal mode with mu4e email client + +EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (require 'mu4e nil t) + (mu4e))" \ No newline at end of file diff --git a/bin/emacs-org b/bin/emacs-org new file mode 100755 index 0000000..c04fc27 --- /dev/null +++ b/bin/emacs-org @@ -0,0 +1,20 @@ +#!/bin/bash +# Launch Emacs in terminal mode with Org mode +# Accepts optional org file argument + +if [ $# -eq 0 ]; then + # No arguments, start with org-agenda + EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (require 'org) + (org-agenda))" +else + # Open specified org file + if [ -f "$1" ]; then + EMACS_NO_DESKTOP=1 emacs -nw "$1" --eval "(org-mode)" + else + # Create new org file + EMACS_NO_DESKTOP=1 emacs -nw "$1" --eval "(progn + (org-mode) + (insert \"#+TITLE: $(basename \"$1\" .org)\n#+DATE: $(date +%Y-%m-%d)\n\n\"))" + fi +fi \ No newline at end of file diff --git a/bin/emacs-portfolio b/bin/emacs-portfolio new file mode 100755 index 0000000..6ad71a0 --- /dev/null +++ b/bin/emacs-portfolio @@ -0,0 +1,6 @@ +#!/bin/bash +# Launch Emacs in terminal mode with portfolio tracker + +EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (when (fboundp 'portfolio-tracker) + (portfolio-tracker)))" \ No newline at end of file diff --git a/bin/emacs-quick b/bin/emacs-quick new file mode 100755 index 0000000..6d8bda8 --- /dev/null +++ b/bin/emacs-quick @@ -0,0 +1,5 @@ +#!/bin/bash +# Launch Emacs in terminal mode with minimal startup (quick mode) +# Useful for quick edits without loading full configuration + +emacs -nw -Q "$@" \ No newline at end of file diff --git a/bin/emacs-terminal b/bin/emacs-terminal new file mode 100755 index 0000000..8c6c018 --- /dev/null +++ b/bin/emacs-terminal @@ -0,0 +1,22 @@ +#!/bin/bash +# Launch Emacs in terminal mode with built-in terminal emulator +# Accepts optional shell command argument + +if [ $# -eq 0 ]; then + # No arguments, start default shell + EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (if (fboundp 'vterm) + (vterm) + (if (fboundp 'term) + (term (getenv \"SHELL\")) + (eshell))))" +else + # Run specified command + CMD="$*" + EMACS_NO_DESKTOP=1 emacs -nw --eval "(progn + (if (fboundp 'vterm) + (vterm) + (if (fboundp 'term) + (term \"$CMD\") + (eshell))))" +fi \ No newline at end of file diff --git a/init.el b/init.el index 4f5f8fb..dd29ee6 100644 --- a/init.el +++ b/init.el @@ -11,10 +11,10 @@ ;; EMERGENCY FIX - Load this first to ensure editing works (require 'init-emergency-fix) -(require 'init-seq-fix) ; Fix seq library issues +;; (require 'init-seq-fix) ; Fix seq library issues ;; Load performance optimizations early -(require 'init-performance) +;; (require 'init-performance) ;;; Load core modules in order (require 'init-core) ; Core settings and package management @@ -165,4 +165,4 @@ "Default portfolio file to load.") (provide 'init) -;;; init.el ends here \ No newline at end of file +;;; init.el ends here diff --git a/lisp/init-core.el b/lisp/init-core.el index 10f5cd0..4885eaf 100644 --- a/lisp/init-core.el +++ b/lisp/init-core.el @@ -133,21 +133,23 @@ (setq desktop-lazy-verbose nil) (setq desktop-lazy-idle-delay 1) ; Restore rest after 1 second idle -;; Enable desktop-save-mode after startup +;; Enable desktop-save-mode after startup (unless disabled via environment) (add-hook 'after-init-hook (lambda () - (desktop-save-mode 1) - (setq desktop-save t) - (setq desktop-auto-save-timeout 300) - (setq desktop-path '("~/.emacs.d/")) - (setq desktop-dirname "~/.emacs.d/") - (setq desktop-base-file-name "emacs-desktop") - (setq desktop-restore-frames t) - ;; Load desktop after a delay - (run-with-idle-timer 2 nil - (lambda () - (desktop-read) - (message "Desktop restored"))))) + ;; Check if desktop mode should be disabled (for helper scripts) + (unless (getenv "EMACS_NO_DESKTOP") + (desktop-save-mode 1) + (setq desktop-save t) + (setq desktop-auto-save-timeout 300) + (setq desktop-path '("~/.emacs.d/")) + (setq desktop-dirname "~/.emacs.d/") + (setq desktop-base-file-name "emacs-desktop") + (setq desktop-restore-frames t) + ;; Load desktop after a delay + (run-with-idle-timer 2 nil + (lambda () + (desktop-read) + (message "Desktop restored")))))) (provide 'init-core) ;;; init-core.el ends here \ No newline at end of file