Skip to content

Instantly share code, notes, and snippets.

@harry-cpp
Last active August 24, 2025 02:08
Show Gist options
  • Save harry-cpp/f8ec780e16201f81ccd5234856546414 to your computer and use it in GitHub Desktop.
Save harry-cpp/f8ec780e16201f81ccd5234856546414 to your computer and use it in GitHub Desktop.

Revisions

  1. harry-cpp revised this gist May 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion VSCodeExtension.py
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,4 @@

    https://github.com/cra0zy/code-nautilus

    since people want to add features to it and no notification arrive from commets on gist.
    since people want to add features to it and no notification arrive from comments on gist.
  2. harry-cpp revised this gist May 16, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion VSCodeExtension.py
    Original file line number Diff line number Diff line change
    @@ -1 +1,5 @@
    Moved to https://github.com/cra0zy/code-nautilus since people want to add features to it and no notification arrive from commets on gist.
    Moved to:

    https://github.com/cra0zy/code-nautilus

    since people want to add features to it and no notification arrive from commets on gist.
  3. harry-cpp revised this gist May 16, 2019. 1 changed file with 1 addition and 69 deletions.
    70 changes: 1 addition & 69 deletions VSCodeExtension.py
    Original file line number Diff line number Diff line change
    @@ -1,69 +1 @@
    # VSCode Nautilus Extension
    #
    # Place me in ~/.local/share/nautilus-python/extensions/,
    # ensure you have python-nautilus package, restrart Nautilus, and enjoy :)
    #
    # Quick install command:
    # mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q
    #
    # Quick download + install command:
    # wget https://gist.github.com/cra0zy/f8ec780e16201f81ccd5234856546414/raw/6e53c15ea4b18de077587e781dc95dc7f0582cc3/VSCodeExtension.py && mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && rm VSCodeExtension.py && nautilus -q
    #
    # This script was written by cra0zy and is released to the public domain

    from gi import require_version
    require_version('Gtk', '3.0')
    require_version('Nautilus', '3.0')
    from gi.repository import Nautilus, GObject
    from subprocess import call
    import os

    # path to vscode
    VSCODE = 'code'

    # what name do you want to see in the context menu?
    VSCODENAME = 'Code'

    # always create new window?
    NEWWINDOW = False


    class VSCodeExtension(GObject.GObject, Nautilus.MenuProvider):

    def launch_vscode(self, menu, files):
    safepaths = ''
    args = ''

    for file in files:
    filepath = file.get_location().get_path()
    safepaths += '"' + filepath + '" '

    # If one of the files we are trying to open is a folder
    # create a new instance of vscode
    if os.path.isdir(filepath) and os.path.exists(filepath):
    args = '--new-window '

    if NEWWINDOW:
    args = '--new-window '

    call(VSCODE + ' ' + args + safepaths + '&', shell=True)

    def get_file_items(self, window, files):
    item = Nautilus.MenuItem(
    name='VSCodeOpen',
    label='Open In ' + VSCODENAME,
    tip='Opens the selected files with VSCode'
    )
    item.connect('activate', self.launch_vscode, files)

    return [item]

    def get_background_items(self, window, file_):
    item = Nautilus.MenuItem(
    name='VSCodeOpenBackground',
    label='Open ' + VSCODENAME + ' Here',
    tip='Opens VSCode in the current directory'
    )
    item.connect('activate', self.launch_vscode, [file_])

    return [item]
    Moved to https://github.com/cra0zy/code-nautilus since people want to add features to it and no notification arrive from commets on gist.
  4. harry-cpp revised this gist Dec 19, 2018. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion VSCodeExtension.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,14 @@
    # VSCode Nautilus Extension
    #
    # Place me in ~/.local/share/nautilus-python/extensions/, ensure you have python-nautilus package, restrart Nautilus, and enjoy :)
    # Place me in ~/.local/share/nautilus-python/extensions/,
    # ensure you have python-nautilus package, restrart Nautilus, and enjoy :)
    #
    # Quick install command:
    # mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q
    #
    # Quick download + install command:
    # wget https://gist.github.com/cra0zy/f8ec780e16201f81ccd5234856546414/raw/6e53c15ea4b18de077587e781dc95dc7f0582cc3/VSCodeExtension.py && mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && rm VSCodeExtension.py && nautilus -q
    #
    # This script was written by cra0zy and is released to the public domain

    from gi import require_version
  5. harry-cpp revised this gist Dec 19, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion VSCodeExtension.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # VSCode Nautilus Extension
    #
    # Place me in ~/.local/share/nautilus-python/extensions/, restrart Nautilus, and enjoy :)
    # Place me in ~/.local/share/nautilus-python/extensions/, ensure you have python-nautilus package, restrart Nautilus, and enjoy :)
    # mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q
    #
    # This script was written by cra0zy and is released to the public domain
  6. harry-cpp revised this gist Apr 19, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion VSCodeExtension.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # VSCode Nautilus Extension
    #
    # Place me in ~/.local/share/nautilus-python/extensions/, restrart Nautilus, and enjoy :)
    # cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q
    # mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q
    #
    # This script was written by cra0zy and is released to the public domain

  7. harry-cpp revised this gist Apr 18, 2018. 1 changed file with 17 additions and 2 deletions.
    19 changes: 17 additions & 2 deletions VSCodeExtension.py
    Original file line number Diff line number Diff line change
    @@ -10,22 +10,37 @@
    require_version('Nautilus', '3.0')
    from gi.repository import Nautilus, GObject
    from subprocess import call
    import os

    # path to vscode
    VSCODE = 'code'

    # what name do you want to see in the context menu?
    VSCODENAME = 'Code'

    # always create new window?
    NEWWINDOW = False


    class VSCodeExtension(GObject.GObject, Nautilus.MenuProvider):

    def launch_vscode(self, menu, files):
    safepaths = ''
    args = ''

    for file in files:
    safepaths += '"' + file.get_location().get_path() + '" '
    filepath = file.get_location().get_path()
    safepaths += '"' + filepath + '" '

    # If one of the files we are trying to open is a folder
    # create a new instance of vscode
    if os.path.isdir(filepath) and os.path.exists(filepath):
    args = '--new-window '

    if NEWWINDOW:
    args = '--new-window '

    call(VSCODE + ' --new-window ' + safepaths + '&', shell=True)
    call(VSCODE + ' ' + args + safepaths + '&', shell=True)

    def get_file_items(self, window, files):
    item = Nautilus.MenuItem(
  8. harry-cpp created this gist Apr 18, 2018.
    48 changes: 48 additions & 0 deletions VSCodeExtension.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    # VSCode Nautilus Extension
    #
    # Place me in ~/.local/share/nautilus-python/extensions/, restrart Nautilus, and enjoy :)
    # cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q
    #
    # This script was written by cra0zy and is released to the public domain

    from gi import require_version
    require_version('Gtk', '3.0')
    require_version('Nautilus', '3.0')
    from gi.repository import Nautilus, GObject
    from subprocess import call

    # path to vscode
    VSCODE = 'code'

    # what name do you want to see in the context menu?
    VSCODENAME = 'Code'


    class VSCodeExtension(GObject.GObject, Nautilus.MenuProvider):

    def launch_vscode(self, menu, files):
    safepaths = ''
    for file in files:
    safepaths += '"' + file.get_location().get_path() + '" '

    call(VSCODE + ' --new-window ' + safepaths + '&', shell=True)

    def get_file_items(self, window, files):
    item = Nautilus.MenuItem(
    name='VSCodeOpen',
    label='Open In ' + VSCODENAME,
    tip='Opens the selected files with VSCode'
    )
    item.connect('activate', self.launch_vscode, files)

    return [item]

    def get_background_items(self, window, file_):
    item = Nautilus.MenuItem(
    name='VSCodeOpenBackground',
    label='Open ' + VSCODENAME + ' Here',
    tip='Opens VSCode in the current directory'
    )
    item.connect('activate', self.launch_vscode, [file_])

    return [item]