'bash: open all django project app file on Mac
I am on a Mac with bash in terminal, I love writing bash scripts to speedup my developing:
.bash_profile
source /Users/qinyiqi/.bashrc
.bashrc
# command style
PS1="🌹 "
export PS1
cls(){
clear; pwd
}
randint(){
echo $(shuf -i $1-$2 -n 1)
}
canvas(){
startm
cd /Applications/MAMP/htdocs/canvas/src
if [ $# -eq 0 ]; then
sublime draw.html
sublime draw.css
sublime draw.js
open "http://localhost:8888/canvas/src/draw.html"
else
if [ ! -f "$1.html" ]; then
# file not found
touch "$1.html"
fi
if [ ! -f "$1.css" ]; then
touch "$1.css"
fi
if [ ! -f "$1.js" ]; then
touch "$1.js"
fi
sublime "$1.html"
sublime "$1.css"
sublime "$1.js"
open "http://localhost:8888/canvas/src/$1.html"
fi
open .
ls
}
now I am working with django, it has a basic app structure such as
.
├── manage.py
├── media
│ └── profile
│ └── default.jpg
├── articles
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── questions
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── tags
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
└── zzd
├── __init__.py
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
basically every apps has similar file structure. in development, I usually need to open all files with the same name, such as models:
- articles.models
- questions.models
- tags.models
to do this, I need to manually click open and close the directories in left panel of vs code, it will be much more convenient if I can just type in cmd something like:
vsdj models
then it checks all apps and open the corresponding file if there is a file named models.py (I am at the same level of all apps).
I had a few goes but all failed, I will be very grateful for any of your help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
