From a1f45666a3bf6b9b09d15de09f9d89efb5fb7d94 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Tue, 24 Apr 2018 08:33:44 +0100 Subject: [PATCH] Update function mycd Change name from cdls Update cd alias If cd fails and the first parameter is a file, it will try and open it in vim --- shells/functions | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/shells/functions b/shells/functions index 2c6dc319..515a31d5 100644 --- a/shells/functions +++ b/shells/functions @@ -34,14 +34,25 @@ function old() { mv "$1" "$1.old" } -function cdls() { - cd "$@" - if [ ! $TMUX ]; then - pwd > ~/.current-folder +function mycd() { + cd "$@" 2> /dev/null + if [ $? = 0 ]; then + # If we get here cd was successful + if [ ! $TMUX ]; then + pwd > ~/.current-folder + fi + ls + else + # If we get here, cd was not successful + if [ -f "$1" ]; then + vim "$1" + else + echo "Can't cd" + exit 1 + fi fi - ls } -alias cd="cdls" +alias cd="mycd" function mkcd() { mkdir -p "$1"