diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-06-11 21:14:07 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-06-11 21:14:07 +0200 |
commit | 5a82c13c615965161eb6ce930f6392ec4849a5e3 (patch) | |
tree | 1f926b325a91fd880874cdbbdb0a22d0cc95890e /config/essentials/zsh/.zshrc | |
parent | 1c154e484b507d0d7a4e6e50b96b1e0b1c7d8c0e (diff) |
added opening textfile by name
Diffstat (limited to 'config/essentials/zsh/.zshrc')
-rw-r--r-- | config/essentials/zsh/.zshrc | 25 |
1 files changed, 24 insertions, 1 deletions
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~ ' |