├── LICENSE ├── README.md ├── aur ├── PKGBUILD └── code-nautilus-git.install ├── code-nautilus.py └── install.sh /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # code-nautilus 2 | 3 | This repo provides a visual studio code extension for Nautilus. 4 | 5 | ## Install Extension 6 | 7 | ``` 8 | wget -qO- https://raw.githubusercontent.com/harry-cpp/code-nautilus/master/install.sh | bash 9 | ``` 10 | 11 | ## Uninstall Extension 12 | 13 | ``` 14 | rm -f ~/.local/share/nautilus-python/extensions/code-nautilus.py 15 | ``` 16 | -------------------------------------------------------------------------------- /aur/PKGBUILD: -------------------------------------------------------------------------------- 1 | # Maintainer: tkit 2 | pkgname=code-nautilus-git 3 | pkgver=r9.ddff975 4 | pkgrel=2 5 | pkgdesc="VSCode extension for Nautilus" 6 | arch=('i686' 'x86_64') 7 | url="https://github.com/cra0zy/code-nautilus" 8 | license=('custom') 9 | depends=('python-nautilus') 10 | makedepends=('git') 11 | optdepends=('code: The Visual Studio Code (vscode) editor') 12 | install="${pkgname}.install" 13 | source=("${pkgname}::git+${url}.git") 14 | md5sums=('SKIP') 15 | pkgver() { 16 | cd "$pkgname" 17 | ( 18 | set -o pipefail 19 | git describe --long 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' || 20 | printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" 21 | ) 22 | } 23 | 24 | package() { 25 | cd "$pkgname" 26 | install -Dm755 code-nautilus.py "$pkgdir/usr/share/nautilus-python/extensions/code-nautilus.py" 27 | install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" 28 | } 29 | -------------------------------------------------------------------------------- /aur/code-nautilus-git.install: -------------------------------------------------------------------------------- 1 | post_install() { 2 | echo "Remember to restart nautilus by running 'nautilus -q'" 3 | } 4 | 5 | post_remove() { 6 | echo "Remember to restart nautilus by running 'nautilus -q'" 7 | } 8 | -------------------------------------------------------------------------------- /code-nautilus.py: -------------------------------------------------------------------------------- 1 | # VSCode Nautilus Extension 2 | # 3 | # Place me in ~/.local/share/nautilus-python/extensions/, 4 | # ensure you have python-nautilus package, restart Nautilus, and enjoy :) 5 | # 6 | # This script is released to the public domain. 7 | 8 | from gi.repository import Nautilus, GObject 9 | from subprocess import call 10 | import os 11 | 12 | # path to vscode 13 | VSCODE = 'code' 14 | 15 | # what name do you want to see in the context menu? 16 | VSCODENAME = 'Code' 17 | 18 | # always create new window? 19 | NEWWINDOW = False 20 | 21 | 22 | class VSCodeExtension(GObject.GObject, Nautilus.MenuProvider): 23 | 24 | def launch_vscode(self, menu, files): 25 | safepaths = '' 26 | args = '' 27 | 28 | for file in files: 29 | filepath = file.get_location().get_path() 30 | safepaths += '"' + filepath + '" ' 31 | 32 | # If one of the files we are trying to open is a folder 33 | # create a new instance of vscode 34 | if os.path.isdir(filepath) and os.path.exists(filepath): 35 | args = '--new-window ' 36 | 37 | if NEWWINDOW: 38 | args = '--new-window ' 39 | 40 | call(VSCODE + ' ' + args + safepaths + '&', shell=True) 41 | 42 | def get_file_items(self, *args): 43 | files = args[-1] 44 | item = Nautilus.MenuItem( 45 | name='VSCodeOpen', 46 | label='Open in ' + VSCODENAME, 47 | tip='Opens the selected files with VSCode' 48 | ) 49 | item.connect('activate', self.launch_vscode, files) 50 | 51 | return [item] 52 | 53 | def get_background_items(self, *args): 54 | file_ = args[-1] 55 | item = Nautilus.MenuItem( 56 | name='VSCodeOpenBackground', 57 | label='Open in ' + VSCODENAME, 58 | tip='Opens the current directory in VSCode' 59 | ) 60 | item.connect('activate', self.launch_vscode, [file_]) 61 | 62 | return [item] 63 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Install python-nautilus 4 | echo "Installing python-nautilus..." 5 | if type "pacman" > /dev/null 2>&1 6 | then 7 | # check if already install, else install 8 | pacman -Qi python-nautilus &> /dev/null 9 | if [ `echo $?` -eq 1 ] 10 | then 11 | sudo pacman -S --noconfirm python-nautilus 12 | else 13 | echo "python-nautilus is already installed" 14 | fi 15 | elif type "apt-get" > /dev/null 2>&1 16 | then 17 | # Find Ubuntu python-nautilus package 18 | package_name="python-nautilus" 19 | found_package=$(apt-cache search --names-only $package_name) 20 | if [ -z "$found_package" ] 21 | then 22 | package_name="python3-nautilus" 23 | fi 24 | 25 | # Check if the package needs to be installed and install it 26 | installed=$(apt list --installed $package_name -qq 2> /dev/null) 27 | if [ -z "$installed" ] 28 | then 29 | sudo apt-get install -y $package_name 30 | else 31 | echo "$package_name is already installed." 32 | fi 33 | elif type "dnf" > /dev/null 2>&1 34 | then 35 | installed=`dnf list --installed nautilus-python 2> /dev/null` 36 | if [ -z "$installed" ] 37 | then 38 | sudo dnf install -y nautilus-python 39 | else 40 | echo "nautilus-python is already installed." 41 | fi 42 | else 43 | echo "Failed to find python-nautilus, please install it manually." 44 | fi 45 | 46 | # Remove previous version and setup folder 47 | echo "Removing previous version (if found)..." 48 | mkdir -p ~/.local/share/nautilus-python/extensions 49 | rm -f ~/.local/share/nautilus-python/extensions/VSCodeExtension.py 50 | rm -f ~/.local/share/nautilus-python/extensions/code-nautilus.py 51 | 52 | # Download and install the extension 53 | echo "Downloading newest version..." 54 | wget -q -O ~/.local/share/nautilus-python/extensions/code-nautilus.py https://raw.githubusercontent.com/harry-cpp/code-nautilus/master/code-nautilus.py 55 | 56 | # Restart nautilus 57 | echo "Restarting nautilus..." 58 | nautilus -q 59 | 60 | echo "Installation Complete" 61 | --------------------------------------------------------------------------------