From 5a82c13c615965161eb6ce930f6392ec4849a5e3 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 11 Jun 2023 21:14:07 +0200 Subject: added opening textfile by name --- config/essentials/zsh/.zshrc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'config/essentials/zsh/.zshrc') diff --git a/config/essentials/zsh/.zshrc b/config/essentials/zsh/.zshrc index 8ba4ece..b603a04 100644 --- a/config/essentials/zsh/.zshrc +++ b/config/essentials/zsh/.zshrc @@ -15,6 +15,20 @@ then exit fi +isTextFile() +{ + if [ -n "$1" ] + then + local file_type=$(file -b --mime-type "$1") + if [[ $file_type == text/* ]] + then + return + else + return 1 + fi + fi +} + autoload -U select-word-style autoload -z edit-command-line zle -N edit-command-line @@ -97,7 +111,16 @@ function osc7 { print -n "\e]7;file://${HOSTNAME}${uri}\e\\" } add-zsh-hook -Uz chpwd osc7 - +command_not_found_handler () { + isTextFile "$1" || + echo "zsh: command not found: $1" >&2 +} +# open file with file name +open_file() { + isTextFile "$1" && + "$EDITOR" "$1" +} +add-zsh-hook -Uz preexec open_file # prompt PS1=' %B%(#.%F{1}.%F{13})[%n%b%f@%B%F{6}%m]%b%f %3~ ' -- cgit v1.2.3