Python Script in VS Code

Automating your Development Process with Fish shell & Python

Use a fish function to kick off your development process. One command will create a React app, create a GitHub repository and start up VS Code!

Christopher Watson
Jun 9 · 3 min read

See my article on creating functions in Fish here


TL;DR

Quickly create a project with one line in your fish terminal

Custom fish function + Python script + Github API = One touch project starter

newproject my-react-project
> Repository my-react-project created

At the conclusion of this script you will have:

1. Project repo in Github
2. Project file folder on local machine
3. Create-react-app boilerplate (with initial commit to Github)
4. VS Code open and ready to go!

Requirements: Python3, pip3, fish shell


Fish Function

Create a basic function to be updated later, after creating the Python Script

Create a function in Fish shell

function newproject
echo “React App”
end

Save the function

funcsave newproject

Python Script

The goal of this script is to use the Github API to log into your account and create a new repository

Navigate to a folder where you store all things code related, create a folder to store your Python scripts

mkdir scripts

Create a new file

touch newProject.py

Install PyGithub

pip install PyGithub

Open your favorite Python IDE and copy the following code

# system imports
import sys
import os
from github import Github

# path to your dev folder — this will need to be updated!
path = “/Users/christopherwatson/Documents/code/”

username = “” # Insert your github username here
password = “” # Insert your github password here

# function to create repo
def create():
# makes a new directory at the selected path and appends new
# project name
os.makedirs(path + str(sys.argv[1]))
# creates a new user object to provide to Github API
user = Github(username, password).get_user()
# creates a repo for the provided user
user.create_repo(sys.argv[1])
# success message!
print(“Succesfully created repository {}”.format(sys.argv[1]))


if __name__ == “__main__”:
create()

Finish Fish Function

Using a parameter, this function will create a folder and repository for development

Navigate to the fish .config folder

cd ~/.config/fish/functions

Edit the function

nano newproject.fish

Insert the following into your .fish file, replacing the path to your Python scripts and Github user name

newproject.fish

In the above code, you are updating the previously created function newproject. Line 2 will check to see if a parameter is passed, and throw an error message if not. Else, we’ll run the script to create a file path and repository based on the argument passed after our function call. We’ll then initialize a local git repository at our new file path, add a new remote, and run create-react-app. Then your new code will be pushed up to the new repository, and VS Code will open at your project location

Using the Function

Quickly create a project with one line in your fish terminal

newProject my-react-project
> Repository my-react-project created

Use this function at any location in your Fish shell!


Christopher Watson

Written by

teacher | full stack web dev | software engineer christopherwatson.co

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade