dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 7a85fbd0b62296a3bea878f83bad8981be684df0
parent ef8f58d7dce19764824c70e456e2332fc3552165
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 15 Mar 2019 09:21:34 +0100

Improve o()

Diffstat:
Mlinks/.commands.sh | 25++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/links/.commands.sh b/links/.commands.sh @@ -34,15 +34,22 @@ alias la='ls -A' ## Open files o() { - [[ "$#" -gt 0 && -f "$1" ]] && (xdg-open "$1" & disown) - - IFS=$'\n' out=($(fzf --query="$1" --exit-0 --expect=ctrl-o,ctrl-e --preview-window=hidden)) - key=$(head -1 <<< "$out") - file=$(head -2 <<< "$out" | tail -1) - if [ -n "$file" ]; then - [ "$key" = ctrl-e ] && \ - ${EDITOR:-vim} "$file" || \ - xdg-open "$file" & disown + [[ "$(uname)" == 'Darwin' ]] && open="open" || open="xdg-open" + if [[ "$#" -gt 0 && -f "$1" ]]; then + nohup $open "$1" & + else + IFS=$'\n' out=($(fzf --query="$1" --exit-0 --expect=ctrl-o,ctrl-e --preview-window=hidden)) + key=$(head -1 <<< "$out") + file=$(head -2 <<< "$out" | tail -1) + if [ -n "$file" ]; then + if [ "$key" = ctrl-e ]; then + ${EDITOR:-vim} "$file" + elif [ "$key" = ctrl-o ]; then + cd "$(dirname "$file")" + else + nohup $open "$file" & + fi + fi fi }