I try to create a atom-editor package which provides its interface through the command palette.
I found the SelectListView class which is exactly what I want but I can't find a documented way to append my own views to the command palette.
Is there a way to do that or is it simply not allowed?
If I understand you correctly, you're trying to add your own commands to the Command Palette. Currently (as of v0.139.0), this is done through the atom.workspaceView.command() method:
atom.workspaceView.command 'package-name:command-name', ->
# Code that you want to execute when the command is called
By convention, the name of all commands follows the pattern package-name:command-name so if your package was named "Foo Bar" and the command was "Frob The Fraggles" then the command name would be foo-bar:frob-the-fraggles.
The command system for packages is going to be updated in the near future, so you may want to watch the Atom repository on GitHub for updates. Even so, the above method should continue to work for a while after the change.
Related
I am using tab completion in a standard Debian install with Bash and I have some files being ignored. For example, if I have the files:
index.php
index.php.a
If I type vim i then tab it immediately selects "index.php " (see space after file name). Normally, it would just complete up to "index.php" and give me the option to type something else after.
Why is it behaving differently in this situation?
Update
Some commands such as "cp" seem to handle the tab completion just fine, so maybe it is vim looking for specific file extensions?
The bash-completion package uses the function _filedir_xspec to complete vim. That function in general completes filenames, but excludes certain patterns depending on which command it is completing.
For vim, the exclusion pattern starts like this:
_install_xspec '*.#([ao]|so|so.!(conf|*/*) ...
I.e., among other things, files ending in .a should be ignored. The thinking behind that is probably that these are often created as backup copies and you probably don't want to edit them.
If you want to override this behaviour, you can add your own completions into ~/.bash_completion; for example, to get vim to complete on all filenames, use this:
complete -f vim
which will make vim tab completion default to the built-in file completion bevahiour.
I am adding commands into my bash profile and am trying to make my code simpler and want to delete the extraneous duplicated code. I have export statements and I have the commands running correctly but I am trying to simplify my code. I am using the same exact code for my commands and want to make it into one file. I am running the commands on a Mac terminal. I have installed npm, atom, atom shell commands and am on Mac OS version 10.14.5.
I tried changing the code structure around but I cannot figure out how to simplify and reuse the commands and make them into a function. The commands are duplicates of each other except that they are pointing to different file paths. I do not want to keep on reusing the same code and I am hoping to make it simpler but not sure how.
export snippet_project="/Users/kevinpleong/Desktop/my-programming-projects/snippet-creator-electronjs"
export programmingprojects="/Users/kevinpleong/Desktop/my-programming-projects"
export personal_website="/Users/kevinpleong/Desktop/my-programming-projects/personal-webiste"
edit-snippet-creator() {
cd /Users/kevinpleong/Desktop/my-programming-projects/snippet-creator-electronjs
atom .
}
edit-personal-website(){
cd /Users/kevinpleong/Desktop/my-programming-projects/personal-website/
atom .
}
edit-programming-projects(){
cd /Users/kevinpleong/Desktop/my-programming-projects/
atom .
}
I am hoping that it outputs the same thing as the bottom 3 blocks of code but I can simplify the code.
The code can be simplified to this:
projects_directory="${HOME}/Desktop/my-programming-projects"
edit-snippet-creator() {
atom "${projects_directory}/snippet-creator-electronjs"
}
edit-personal-website(){
atom "${projects_directory}/personal-website"
}
edit-programming-projects(){
atom "$projects_directory"
}
The exports are redundant
The variables are redundant since they would only each be used once. Only the projects directory is reused.
Trailing slashes are unnecessary.
Use More Quotes™.
That said, as you get used to the shell I expect you'll want to move away from patterns like this, because they are a premature abstraction and they hinder you from learning all the powerful built-in features of the shell, such as Tab completion. For example, if you've already edited a project you can press Ctrl-r to search the command history for the name of that project. Also, I expect atom, like every sane shell command, can take a directory different from the current one as the target, so you can simply type atom ~/Desktop/my, press Tab to complete atom ~/Desktop/my-programming-projects/, and press Tab again to see which projects are available.
I was wondering if it was possible to manipulate the number of characters typed as a command. The reason for this, is I am writing a custom function to complete commands (when you press TAB), but I am using the complete function only for prompting the user, and not completing. What I want to be able to do is complete a typed word as such:
User$ command param[TAB]
prefixparam aaaparambbb
User$ command param
User$ command aparam[TAB]
User$ command aaaparambbb
Since I am completing the param as the prefix and suffix (and in some cases replacing it entirely), I can't use the builtin complete functionality, and instead I am looking for a workaround (hopefully without getting too deep).
How my current function works
When you press tab, it will parse the command and determine the possible completions. Then it will type the bash prompt again ($PS1) and the part of the command that was typed already. (User$ command param)
I want it so that when there is only 1 possible option, for it to replace your partial command with the only remaining option. This is already possible since I am manually reprompting the user, but I am having problems since the shell will not allow you to backspace more than you typed originally.
User$ command aparam[TAB]
User$ command aaapa[rambbb] // Can only backspace 6 characters
I need some way to trick the shell into thinking that all 11 characters were typed and can be deleted.
=========================================================================
I have found almost what I wanted to be possible using bind for anyone interested: bash expand cd with shortcuts like zsh
You can modify the $READLINE_LINE and $READLINE_POINT variables to modify the command. However, this only works for bind commands, and binding to TAB would overwrite and break other autocomplete functions which I would prefer not to.
I have a project with a deeply nested folder structure. Most of the time I know the name of the file I want to work with, but the folder path is too long/complicated to type when I want to edit it, like:
vim folder/is/deep/down/there/myfile.js
Is there a way to make the shell auto populate the path for me if the filename is unique, with something like:
vim *myfile.js
press TAB -->
vim folder/is/deep/down/there/myfile.js
I mostly use bash, but I'm fine with zsh if it can solve the problem.
I think this is what you're looking for, vim will open all instances of myfile.js in the directory. Fish shell will allow me to tab through the different matching files but I'm not sure it that works with bash.
vim **/myfile.js
What could be a good idea would be to use locate utility in a bash script.
Calling your bash script passing filename as argument would be a smart move, and then using the previously named utility to find it.
Having done that you could simply find if there was 1 or more matches, and if there's just a match you can just use vim [match].
And obviously, the script could be called like ./openinvim.sh myfile.js
I often create a temporary mapping to do something on a particular file.
Typical example is this:
:map <leader>f :w<cr>:! bundle exec cucumber features/account/sign_in.feature:41<cr>
I want the file features/account/sign_in.feature to be autocompleted from the current directory.
This should simply save the current file and shell out on <leader>f to run the command.
It allows me to easily work on a piece of code not thinking about jumping to a particular file and run it.
The problem is that creating such a binding is cumbersome and error prone.
VIM doesn't allow completing the file name when mapping. Also using % is totally different ( I want to map to a file statically).
What is a better way of doing it?
Thanks.
Allthough I think your question should be made a lot clearer, here are some hints:
:nnoremap <leader>f :w<bar>!exec "bundle exec cucumber " . expand('%') . ":" . line('.')<CR>
Will correctly save and insert current filename/line number in the command
Also, you will want to know about the autowrite option:
:se autowrite
Lastly, I usually employ makeprg for this kind of purpose:
:let &makeprg="bundle exec cucumber %"
This has the added benefit of working with quickfix commands (:copen, :colder, :cnewer) and (given a correct makef) also jumping to error lines
I don't know the answer but if I were you I'd use cabbr:
:cabbr fas features/account/sign_in.features:
Or something like that. It's not autocomplete, but it sure does reduce the number of keystrokes you need.
Another alternative is to create a function mapped from a user command that accepts an argument that creates the mapping. If I remember it correctly you can customize the user command completion so that might work.
Update: yes you can customize user command. See :help user-command
Something like this should get you started:
command -complete=file_in_path -nargs=1 Map call CreateMap(expand('<args>'))
function CreateMap(filename)
exec 'map <leader>f :w<cr>:! bundle exec cucumber ' . a:filename . ':41<cr>'
endfun
Once you do that, ensure that you 'path' setting includes the current directory ".", or if you want to make it search recursively "./**". Then you can use the Map user command like this:
:Map fea<tab>ac<tab>