i need to write a bash function that wraps nano such that if the only argument is a directory, it cds there instead

i keep typing nano directoryname/ and absentmindedly hitting enter while thinking about what comes next in the path

@monorail One-liner for your ~/.bashrc:

nano() { if [ -d ${!#} ]; then cd ${!#}; else /usr/bin/nano $@; fi }

It checks the last argument, whether it's the only one or not.

Follow

@monorail Mastodon keeps eating the open-bracket between "if" and "-d".

@arielmt @monorail also shouldn't $@ have "" around it? maybe both ${!#} too

Sign in to participate in the conversation
Computer Fairies

Computer Fairies is a Mastodon instance that aims to be as queer, friendly and furry as possible. We welcome all kinds of computer fairies!