diff --git a/build/gulpfile.hygiene.js b/build/gulpfile.hygiene.js index 09b4b80b572..1af30179a06 100644 --- a/build/gulpfile.hygiene.js +++ b/build/gulpfile.hygiene.js @@ -114,6 +114,7 @@ const copyrightFilter = [ '!resources/linux/snap/snapcraft.yaml', '!resources/linux/snap/electron-launch', '!resources/win32/bin/code.js', + '!resources/completions/**', '!extensions/markdown-language-features/media/highlight.css', '!extensions/html-language-features/server/src/modes/typescript/*', '!extensions/*/server/bin/*' diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js index e9cba1cd25f..d68e419c570 100644 --- a/build/gulpfile.vscode.js +++ b/build/gulpfile.vscode.js @@ -385,6 +385,8 @@ function packageTask(platform, arch, opts) { .pipe(electron(_.extend({}, config, { platform, arch, ffmpegChromium: true }))) .pipe(filter(['**', '!LICENSE', '!LICENSES.chromium.html', '!version'])); + result = es.merge(result, gulp.src('resources/completions/**', { base: '.' })); + if (platform === 'win32') { result = es.merge(result, gulp.src('resources/win32/bin/code.js', { base: 'resources/win32' })); diff --git a/build/gulpfile.vscode.linux.js b/build/gulpfile.vscode.linux.js index 33972ba398b..fae082779d7 100644 --- a/build/gulpfile.vscode.linux.js +++ b/build/gulpfile.vscode.linux.js @@ -53,6 +53,12 @@ function prepareDebPackage(arch) { const icon = gulp.src('resources/linux/code.png', { base: '.' }) .pipe(rename('usr/share/pixmaps/' + product.applicationName + '.png')); + const bash_completion = gulp.src('resources/completions/bash/code') + .pipe(rename('usr/share/bash-completion/completions/code')); + + const zsh_completion = gulp.src('resources/completions/zsh/_code') + .pipe(rename('usr/share/zsh/vendor-completions/_code')); + const code = gulp.src(binaryDir + '/**/*', { base: binaryDir }) .pipe(rename(function (p) { p.dirname = 'usr/share/' + product.applicationName + '/' + p.dirname; })); @@ -87,7 +93,7 @@ function prepareDebPackage(arch) { .pipe(replace('@@UPDATEURL@@', product.updateUrl || '@@UPDATEURL@@')) .pipe(rename('DEBIAN/postinst')); - const all = es.merge(control, postinst, postrm, prerm, desktops, appdata, icon, code); + const all = es.merge(control, postinst, postrm, prerm, desktops, appdata, icon, bash_completion, zsh_completion, code); return all.pipe(vfs.dest(destination)); }; @@ -137,6 +143,12 @@ function prepareRpmPackage(arch) { const icon = gulp.src('resources/linux/code.png', { base: '.' }) .pipe(rename('BUILD/usr/share/pixmaps/' + product.applicationName + '.png')); + const bash_completion = gulp.src('resources/completions/bash/code') + .pipe(rename('BUILD/usr/share/bash-completion/completions/code')); + + const zsh_completion = gulp.src('resources/completions/zsh/_code') + .pipe(rename('BUILD/usr/share/zsh/site-functions/_code')); + const code = gulp.src(binaryDir + '/**/*', { base: binaryDir }) .pipe(rename(function (p) { p.dirname = 'BUILD/usr/share/' + product.applicationName + '/' + p.dirname; })); @@ -157,7 +169,7 @@ function prepareRpmPackage(arch) { const specIcon = gulp.src('resources/linux/rpm/code.xpm', { base: '.' }) .pipe(rename('SOURCES/' + product.applicationName + '.xpm')); - const all = es.merge(code, desktops, appdata, icon, spec, specIcon); + const all = es.merge(code, desktops, appdata, icon, bash_completion, zsh_completion, spec, specIcon); return all.pipe(vfs.dest(getRpmBuildPath(rpmArch))); }; diff --git a/resources/completions/bash/code b/resources/completions/bash/code new file mode 100644 index 00000000000..e377c5d24e2 --- /dev/null +++ b/resources/completions/bash/code @@ -0,0 +1,61 @@ +_code() +{ + local cur prev words cword split + _init_completion -s || return + + _expand || return + + case $prev in + -d|--diff) + _filedir + return + ;; + -a|--add|--user-data-dir|--extensions-dir) + _filedir -d + return + ;; + -g|--goto) + compopt -o nospace + _filedir + return + ;; + --locale) + COMPREPLY=( $( compgen -W 'de en en-US es fr it ja ko ru zh-CN zh-TW bg hu pt-br tr' ) ) + return + ;; + --install-extension|--uninstall-extension) + _filedir vsix + return + ;; + --log) + COMPREPLY=( $( compgen -W 'critical error warn info debug trace off' ) ) + return + ;; + --folder-uri|--disable-extension|--max-memory) + # argument required but no completions available + return 0 + ;; + --enable-proposed-api) + # argument optional but no completions available + ;; + esac + + $split && return + + if [[ $cur == -* ]]; then + COMPREPLY=( $( compgen -W '-d --diff --folder-uri -a --add -g + --goto -n --new-window -r --reuse-window -w --wait --locale= + --user-data-dir -v --version -h --help --extensions-dir + --list-extensions --show-versions --install-extension + --uninstall-extension --enable-proposed-api --verbose --log -s + --status -p --performance --prof-startup --disable-extensions + --disable-extension --inspect-extensions + --inspect-brk-extensions --disable-gpu --upload-logs + --max-memory=' -- "$cur") ) + [[ $COMPREPLY == *= ]] && compopt -o nospace + return + fi + + _filedir +} && +complete -F _code code diff --git a/resources/completions/zsh/_code b/resources/completions/zsh/_code new file mode 100644 index 00000000000..9579cffb2f6 --- /dev/null +++ b/resources/completions/zsh/_code @@ -0,0 +1,38 @@ +#compdef code + +local arguments + +arguments=( + '(-d --diff)'{-d,--diff}'[compare two files with each other]:file to compare:_files:file to compare with:_files' + \*'--folder-uri[open a window with given folder uri(s)]:folder uri: ' + \*{-a,--add}'[add folder(s) to the last active window]:directory:_directories' + '(-g --goto)'{-g,--goto}'[open a file at the path on the specified line and column position]:file\:line[\:column]:_files -r \:' + '(-n --new-window -r --reuse-window)'{-n,--new-window}'[force to open a new window]' + '(-n --new-window -r --reuse-window)'{-r,--reuse-window}'[force to open a file or folder in an already opened window]' + '(-w --wait)'{-w,--wait}'[wait for the files to be closed before returning]' + '--locale=[the locale to use (e.g. en-US or zh-TW)]:locale (e.g. en-US or zh-TW):(de en en-US es fr it ja ko ru zh-CN zh-TW bg hu pt-br tr)' + '--user-data-dir[specify the directory that user data is kept in]:directory:_directories' + '(- *)'{-v,--version}'[print version]' + '(- *)'{-h,--help}'[print usage]' + '--extensions-dir[set the root path for extensions]:root path:_directories' + '--list-extensions[list the installed extensions]' + '--show-versions[show versions of installed extensions, when using --list-extension]' + '--install-extension[install an extension]:id or path:_files -g "*.vsix(-.)"' + '--uninstall-extension[uninstall an extension]:id or path:_files -g "*.vsix(-.)"' + '--enable-proposed-api[enables proposed API features for extensions]::extension id: ' + '--verbose[print verbose output (implies --wait)]' + '--log[log level to use]:level [info]:(critical error warn info debug trace off)' + '(-s --status)'{-s,--status}'[print process usage and diagnostics information]' + '(-p --performance)'{-p,--performance}'[start with the "Developer: Startup Performance" command enabled]' + '--prof-startup[run CPU profiler during startup]' + '(--disable-extension --disable-extensions)--disable-extensions[disable all installed extensions]' + \*'--disable-extension[disable an extension]:extension id: ' + '--inspect-extensions[allow debugging and profiling of extensions]' + '--inspect-brk-extensions[allow debugging and profiling of extensions with the extension host being paused after start]' + '--disable-gpu[disable GPU hardware acceleration]' + '--upload-logs[upload logs from current session to a secure endpoint]:confirm:(iConfirmLogsUpload)' + '--max-memory=[max memory size for a window (in Mbytes)]:size (Mbytes)' + '*:file or directory:_files' +) + +_arguments -s -S $arguments diff --git a/resources/linux/rpm/code.spec.template b/resources/linux/rpm/code.spec.template index 71e016614e2..c3ce219f28f 100644 --- a/resources/linux/rpm/code.spec.template +++ b/resources/linux/rpm/code.spec.template @@ -18,10 +18,14 @@ Visual Studio Code is a new choice of tool that combines the simplicity of a cod mkdir -p %{buildroot}/usr/share/@@NAME@@ mkdir -p %{buildroot}/usr/share/applications mkdir -p %{buildroot}/usr/share/pixmaps +mkdir -p %{buildroot}/usr/share/bash-completion/completions +mkdir -p %{buildroot}/usr/share/zsh/site-functions cp -r usr/share/@@NAME@@/* %{buildroot}/usr/share/@@NAME@@ cp -r usr/share/applications/@@NAME@@.desktop %{buildroot}/usr/share/applications cp -r usr/share/applications/@@NAME@@-url-handler.desktop %{buildroot}/usr/share/applications cp -r usr/share/pixmaps/@@NAME@@.png %{buildroot}/usr/share/pixmaps +cp usr/share/bash-completion/completions/code %{buildroot}/usr/share/bash-completion/completions/code +cp usr/share/zsh/site-functions/_code %{buildroot}/usr/share/zsh/site-functions/_code %post # Remove the legacy bin command if this is the stable build @@ -54,3 +58,5 @@ fi /usr/share/applications/@@NAME@@.desktop /usr/share/applications/@@NAME@@-url-handler.desktop /usr/share/pixmaps/@@NAME@@.png +/usr/share/bash-completion/completions/code +/usr/share/zsh/site-functions/_code