I have following setup:
In my ~/.bashrc I only call a script, where my actual settings are stored in:
source C:/path/To/mybashrc.sh As you might see I use the git-bash for Windows (not sure, if that is important):
$ bash --version GNU bash, version 4.4.23(1)-release (x86_64-pc-msys) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Now I want to create a command, that makes me able to edit this script directly. I found out how to get the directory of the script (1) and in another post I found out how to get the scripts name itself (2).
# Edit this file with nano #(1) __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" #(2) script_name=`basename "$0"` # script_name="mybashrc.sh" # This works. alias mybashrc='nano ${__dir}/${script_name}' However my problem is that I can't combine these two solutions. When I try the script it opens a file called bash in the right directory in nano and not mybashrc.sh. The problem is probably the sourcing of the script in .bashrc and I wonder if I can still get to the desired solution. I am looking forward towards any hints. (Of course the out-commented line works as the name is hard-coded, but that is not a solution for me as the script names differ in the real-world scenario, that I have.)
alias mybashrc='nano C:/path/To/mybashrc.sh'?nanowithechoand tell us what you get when you do what you want.$0will name an executable script, not one you have sourced. If the path is hardcoded in bashrc then get it from there. The better solution is to symlink~/.bashrcto the script you want to use, instead of a single line which sources it. Then you'll have a consistent reference.C:/path/To/bash