174 lines
8.1 KiB
EmacsLisp
174 lines
8.1 KiB
EmacsLisp
|
;;; bundle--linux.el --- A bundle of useful Linux information
|
||
|
|
||
|
;;; Commentary:
|
||
|
;; This file contains a variety of Emacs Lisp functions that provide
|
||
|
;; helpful descriptions for Linux directories, commands, and options.
|
||
|
|
||
|
;;; Code:
|
||
|
|
||
|
(defvar linux-filesystem-alist
|
||
|
'(( "/" . "Root directory, the base of the filesystem hierarchy")
|
||
|
("/bin" . "Essential command binaries, needed for booting")
|
||
|
("/boot" . "Bootloader files, kernel, and other files needed during booting")
|
||
|
("/dev" . "Device files representing hardware components")
|
||
|
("/etc" . "System-wide configuration files")
|
||
|
("/home" . "User home directories")
|
||
|
("/lib" . "Shared libraries and kernel modules")
|
||
|
("/media" . "Mount points for removable media like CDs and USBs")
|
||
|
("/mnt" . "Temporary mount points for filesystems")
|
||
|
("/opt" . "Optional application software packages")
|
||
|
("/proc" . "Virtual filesystem providing info about processes and system")
|
||
|
("/root" . "Home directory for the root user")
|
||
|
("/sbin" . "Essential system binaries, usually for the root user")
|
||
|
("/srv" . "Data directories for services like HTTP, FTP, etc.")
|
||
|
("/sys" . "Virtual filesystem for kernel objects")
|
||
|
("/tmp" . "Temporary files, cleared on reboot")
|
||
|
("/usr" . "User binaries, documentation, libraries, etc.")
|
||
|
("/var" . "Variable files like logs, databases, etc."))
|
||
|
"Alist mapping Linux directories to their descriptions.")
|
||
|
|
||
|
(defun describe-linux-directory (dirname)
|
||
|
"Describe the purpose of a Linux directory.
|
||
|
Takes DIRNAME as an argument and prints its description."
|
||
|
(interactive "sEnter Linux directory name (e.g., /bin): ")
|
||
|
(let ((description (assoc-default dirname linux-filesystem-alist)))
|
||
|
(if description
|
||
|
(message "%s: %s" dirname description)
|
||
|
(message "Unknown directory: %s" dirname))))
|
||
|
|
||
|
(defvar bash-regex-alist
|
||
|
'(("empty line" . "^$")
|
||
|
("backslash" . "\\\\")
|
||
|
("line starts with a dot" . "^\\.")
|
||
|
("line ends with a dot" . "\\.$")
|
||
|
("line starts with a dollar sign" . "^\\$")
|
||
|
("line starts with a caret" . "^\\^")
|
||
|
("left square bracket" . "\\[")
|
||
|
("right square bracket" . "\\]")
|
||
|
("entire line" . "^.*$")
|
||
|
("any alphanumeric character" . "[a-zA-Z0-9]")
|
||
|
("IP Address" . "\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b")
|
||
|
("email" . "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}")
|
||
|
("hex color code" . "#[a-fA-F0-9]{6}")
|
||
|
("date in yyyy-mm-dd" . "\\b\\d{4}-\\d{2}-\\d{2}\\b")
|
||
|
("time in hh:mm:ss" . "\\b\\d{2}:\\d{2}:\\d{2}\\b")
|
||
|
("words without vowels" . "\\b[^aeiou\s]+\\b"))
|
||
|
"Alist mapping Bash regular expressions to their descriptions.")
|
||
|
|
||
|
(defun describe-bash-regex (regex)
|
||
|
"Describe the purpose of a Bash regular expression.
|
||
|
Takes REGEX as an argument and prints its description."
|
||
|
(interactive "sEnter Bash regex (e.g., empty line): ")
|
||
|
(let ((description (assoc-default regex bash-regex-alist)))
|
||
|
(if description
|
||
|
(message "%s: %s" regex description)
|
||
|
(message "Unknown regular expression: %s" regex))))
|
||
|
|
||
|
(defvar linux-process-commands-alist
|
||
|
'(("ps" . "Shows a snapshot of the current processes")
|
||
|
("top" . "Displays dynamic real-time view of system stats and processes")
|
||
|
("htop" . "An interactive process viewer, similar to top but more feature-rich")
|
||
|
("pgrep" . "Looks up processes based on name and other attributes")
|
||
|
("pstree" . "Displays the process tree in a tree-like diagram")
|
||
|
("ps -e" . "Lists all the processes running on the system")
|
||
|
("ps aux" . "Displays detailed information about all processes")
|
||
|
("kill" . "Terminates processes by sending signals")
|
||
|
("killall" . "Kills all processes that match the given name")
|
||
|
("pkill" . "Send signals to processes based on name and other attributes"))
|
||
|
"Alist mapping Linux process-checking commands to their descriptions.")
|
||
|
|
||
|
(defun describe-linux-process-command (command)
|
||
|
"Describe the purpose of a Linux process-checking command.
|
||
|
Takes COMMAND as an argument and prints its description."
|
||
|
(interactive "sEnter Linux process command (e.g., ps): ")
|
||
|
(let ((description (assoc-default command linux-process-commands-alist)))
|
||
|
(if description
|
||
|
(message "%s: %s" command description)
|
||
|
(message "Unknown command: %s" command))))
|
||
|
|
||
|
(defvar linux-logfiles-alist
|
||
|
'(("/var/log/syslog" . "System messages, including the messages that are logged during system startup")
|
||
|
("/var/log/auth.log" . "Security/authorization information, including user logins and authentication")
|
||
|
("/var/log/kern.log" . "Kernel logs")
|
||
|
("/var/log/cron.log" . "Logs for cron jobs")
|
||
|
("/var/log/messages" . "General system activity logs")
|
||
|
("/var/log/boot.log" . "System boot log")
|
||
|
("/var/log/daemon.log" . "Background daemon log messages")
|
||
|
("/var/log/dpkg.log" . "Logs for package installations and removals")
|
||
|
("/var/log/mail.log" . "Mail server logs")
|
||
|
("/var/log/user.log" . "User-level messages"))
|
||
|
"Alist mapping Linux log files to their descriptions.")
|
||
|
|
||
|
(defun describe-linux-logfile (logfile)
|
||
|
"Describe the purpose of a Linux log file.
|
||
|
Takes LOGFILE as an argument and prints its description."
|
||
|
(interactive "sEnter Linux log file path (e.g., /var/log/syslog): ")
|
||
|
(let ((description (assoc-default logfile linux-logfiles-alist)))
|
||
|
(if description
|
||
|
(message "%s: %s" logfile description)
|
||
|
(message "Unknown log file: %s" logfile))))
|
||
|
|
||
|
(defvar linux-basic-commands-alist
|
||
|
'(("ls" . "List directory contents")
|
||
|
("cd" . "Change directory")
|
||
|
("mv" . "Move or rename files")
|
||
|
("cp" . "Copy files")
|
||
|
("rm" . "Remove files or directories")
|
||
|
("pwd" . "Print working directory")
|
||
|
("echo" . "Display a line of text or a variable value")
|
||
|
("touch" . "Create an empty file or update the access/modification time of a file")
|
||
|
("chmod" . "Change file permissions")
|
||
|
("chown" . "Change file ownership"))
|
||
|
"Alist mapping basic Linux commands to their descriptions.")
|
||
|
|
||
|
(defun describe-basic-linux-command (command)
|
||
|
"Describe the purpose of a basic Linux command.
|
||
|
Takes COMMAND as an argument and prints its description."
|
||
|
(interactive "sEnter basic Linux command (e.g., ls): ")
|
||
|
(let ((description (assoc-default command linux-basic-commands-alist)))
|
||
|
(if description
|
||
|
(message "%s: %s" command description)
|
||
|
(message "Unknown command: %s" command))))
|
||
|
|
||
|
(defvar chown-options-alist
|
||
|
'(("-R" . "Operate on files and directories recursively")
|
||
|
("--from" . "Change the owner and/or group of each file only if its current owner and/or group match specified values")
|
||
|
("--no-dereference" . "Affect symbolic links instead of the files they point to")
|
||
|
("--preserve-root" . "Fail when attempting to operate recursively on '/'")
|
||
|
("--reference" . "Use owner and group of a reference file")
|
||
|
("-c" . "Report when a change is made")
|
||
|
("-f" . "Suppress most error messages")
|
||
|
("-v" . "Output a diagnostic for every file processed"))
|
||
|
"Alist mapping chown command options to their descriptions.")
|
||
|
|
||
|
(defun describe-chown-option (option)
|
||
|
"Describe the purpose of a chown option.
|
||
|
Takes OPTION as an argument and prints its description."
|
||
|
(interactive "sEnter chown option (e.g., -R): ")
|
||
|
(let ((description (assoc-default option chown-options-alist)))
|
||
|
(if description
|
||
|
(message "%s: %s" option description)
|
||
|
(message "Unknown chown option: %s" option))))
|
||
|
|
||
|
(defvar chmod-options-alist
|
||
|
'(("-R" . "Operate on files and directories recursively")
|
||
|
("--preserve-root" . "Avoid operating recursively on '/'")
|
||
|
("-c" . "Report when a change is made")
|
||
|
("-f" . "Suppress most error messages")
|
||
|
("-v" . "Output a diagnostic for every file processed")
|
||
|
("--reference" . "Use mode of a reference file")
|
||
|
("-w" . "Remove write permission")
|
||
|
("-x" . "Remove execute permission")
|
||
|
("-u" . "Set user ID on execution")
|
||
|
("-g" . "Set group ID on execution"))
|
||
|
"Alist mapping chmod command options to their descriptions.")
|
||
|
|
||
|
(defun describe-chmod-option (option)
|
||
|
"Describe the purpose of a chmod option.
|
||
|
Takes OPTION as an argument and prints its description."
|
||
|
(interactive "sEnter chmod option (e.g., -R): ")
|
||
|
(let ((description (assoc-default option chmod-options-alist)))
|
||
|
(if description
|
||
|
(message "%s: %s" option description)
|
||
|
(message "Unknown chmod option: %s" option))))
|