diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-07-01 10:40:01 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-07-01 10:40:01 +0200 |
commit | e7ebdcd1ed66f9833906fbf154607cdbd46fdae2 (patch) | |
tree | d857f3a5a219a038a77113d8d412c824b225e56d /config/essentials/zsh/.zshrc | |
parent | e0fab4836639db0c9b4719551aa24cc26850b358 (diff) | |
parent | b3e19b6a7c1ab3ea8fefc60352ace64a560b46cd (diff) |
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'config/essentials/zsh/.zshrc')
-rw-r--r-- | config/essentials/zsh/.zshrc | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/config/essentials/zsh/.zshrc b/config/essentials/zsh/.zshrc index 8ba4ece..83da0f6 100644 --- a/config/essentials/zsh/.zshrc +++ b/config/essentials/zsh/.zshrc @@ -28,7 +28,7 @@ zle -N add-surround surround zle -N change-surround surround compinit -if grep -qi "debian\|ubuntu" /etc/os-release 2> /dev/null +if grep -qi "debian\|ubuntu" /etc/os-release 2>/dev/null then sfiles=( /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh @@ -65,6 +65,21 @@ bindkey "^Xe" edit-command-line bindkey "^[." insert-last-word bindkey "^['" quote-line +isTextFile() +{ + if [ ! -f "$1" ] + then + return 1 + fi + + file_type=$(file -b --mime-type "$1") + if [[ "$file_type" == text/* ]] + then + return + fi + return 1 +} + # rehash hook zshcache_time="$(date +%s%N)" autoload -Uz add-zsh-hook @@ -97,7 +112,18 @@ 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() { + if [ ${1:0:2} != "./" ] && isTextFile "$1" + then + "$EDITOR" "$1" + fi +} +add-zsh-hook -Uz preexec open_file # prompt PS1=' %B%(#.%F{1}.%F{13})[%n%b%f@%B%F{6}%m]%b%f %3~ ' |