Creating shorthands for commands in vscode terminal? - terminal

It is possible to create git shorthands by defining alias in .gitconfig.
Is there a similar facility for all command line options. Say I am not interested in typing npm run build && node index.js, is there an option to define this with a short hand like bld-run.
I know this is theoretically possible but can't find clear documentation for this.
Please point me in the right direction.

Thank u for the tip #alex. Posting the answer for future enthusiasts.
In mac os mojave, open ~/.bash_profile in any text editor.
type as follows alias c="clear" and save the file.
Open new terminal and type c and your terminal will be all clear.
Same goes for other commands as well.

Related

Need to update shell in PyCharm to zsh

Started taking the 'Programming for everyone' course on Coursera to learn python. Ive downloaded 2 text editors. Atom and Pycharm. When I open the terminal both say, "The default interactive shell is now zsh. To update your account to use zsh, please run chsh -s /bin/zsh."
Please understand I'm totally new. This is the first time I've ever used a text editor or terminal so don't know where to run this or how to straighten this out. Im using a 2015 MacBook Pro running 10.15.7Image is screenshot of editor and terminal in pycahrm im in.
Yeah, it sucks. I had the same problem with Pycharm, but this solution worked for me.
1- Change zsh to bash
$ /bin/bash
2 - Get the commands back like (cd, ls, clear ...)
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
3 - Get the profile back
. /etc/profile
After that your porfile will look like this "username:" instead of this "%n#%m %1~ %#"
One more thing, if you using mac, open your terminal and check preference. In the preferences go to General -> Shells open with -> if it is Default Login shell which means you are using zsh, you should change to Command (complete path): and add /bin/bash in the space below so that your default change to bash.
I hope it was useful for you, and for the people looking for answers. Cause, I wasted an hour looking for solution that JetBrain Pycharm and Apple couldn't provide.

how do you enable command line editing with vim keys using mac terminal?

I'm reading this book and I really do not understand what this author is talking about. It appears that you can program your mac to go forward one character by either hitting l or ^F. I do not understand the difference between emac key stroke and vim keystroke. He also says run this command and 'place it in your $HOME/.bash_profile but I cannot figure out how to place the command in the bas_profile.
The Author is talking about make you terminal console behaves like vi, this means typing set -o vi in your terminal, the console will work similar vi. So you will be able to navigate using the motion keys of vi, use INSERT mode, x to delete, etc.
You can set that permanently if you include this command in your ~/.bash_profile file.
If you are not sure what it does, I don't recommend so.

Textmate tutorial terminal mac-osx

I have installed Textmate editor on my terminal and I am looking for some tutorial to discover Textmate's command lines ? Does anyone has a some links ?
Best,
Newben
The textmate bin that is optionally installed for command line access is really nothing but a simple manner to open files in the OSX gui application.
That said, there are a few handy shortcuts. -w issues a "wait" while opening the file, thus following commands in a sequence will wait until the document is closed to execute. For example:
alias bashrc="mate -w ~/.bashrc; source ~/.bashrc"
That said, if you are looking for a good command set for using within the gui itself, let me know and I will fill in a list of handy commands (it has been my default editor for 6 years now).
Edit: Here are the beginnings of my TextMate docs. I currently have the Cheat Sheet in a state that should prove useful. I will be adding to it and writing up some more extensive docs in the near future.
TextMate Cheat Sheet
You can invoke it from the command line with:
mate path/to/file/you/want/to/edit.txt
You can use more than one file, space separated. To see more options do:
mate --help
This if you installed the commandline option. which you can also do from preferences at any time (its just a symlink)

Why does git diff on Windows warn that the "terminal is not fully functional"?

I'm using msysgit 1.7.7.1 on Windows. I get an error when using git diff. What is causing this? Is there no diff tool included in msysgit? What should I do?
WARNING: terminal is not fully functional
If you are having issues in cmd.exe, for instance, see the warning here:
Then simply set your environment variables and include TERM=msys. After that, each time you open a cmd.exe, your variable will be set correctly.
NOW YOU MUST RESTART YOUR SHELL (CMD.EXE). Just run a new one. And from there, you should have no more issues. Again:
For Git Bash, this can be fixed by adding the following line to ~/.bashrc:
export TERM=cygwin
-or-
export TERM=msys
The first seems to be the original by git for windows, the second a popular known form to "heal" as well.
The problem can be caused if some other program (like for example Strawberry Perl) sets the TERM system environment variables.
http://code.google.com/p/msysgit/issues/detail?id=184
Above answers was not fully worked for me, so I did:
Add
export TERM=msys
to "[githome]/etc/profile" at the top but it made changes only for git bash. Then I added
#set TERM=msys
to "[githome]/cmd/git.cmd" after #setlocal (I installed only git run from command line). May be this decision not truly good but it works for me and there are not any terminal warnings. (I use git version 1.7.10.msysgit.1).
The answer can be found here, in which the author of the solution claims that:
the environment variable TERM was set to dumb
that was instead of
TERM=cygwin
You can change that to
TERM=msys
to solve the problem at hand.
I work in powershell and I have the git executable directly in my path.
None of the suggested answers worked, but I found a solution that works for me.
I added a line in my powershell profile:
$env:TERM="msys"
Which fixed the problem for me.
A quick & dirty solution in my case turned out to be to use the --no-pager option.
By default, some git commands (like log) will use a pager like less if they expect the output to be long. Pagers require things like scrolling text up and down with the arrow keys, which sometimes doesn't work if the assumptions about what kind of terminal you're on are wrong (this is what the "not fully functional" means).
If you know ahead of time that your output will be short, or you just want it to dump output to the terminal and leave the scrolling up to your terminal program, you can override this and not use a pager at all, e.g.:
git --no-pager log
In case someone gets this launching bash from Git Extensions, check the setting for Path to linux tools.... Mine was set to C:\cygwin. Changing it to C:\Program Files (x86)\Git\bin\ fixed it for me. I didn't have to set the TERM variable to launch bash this way.

is there a way to add current working directory/current git repo/branch in terminal prompt for Mac

first time poster.
This came up in conversation at work this week...
Is there a way, when you connect to git remotely that you can get display current working directory/current git repo/branch in your terminal prompt?
Apparently, there are linux/vim scripts that exist for linux users, and I'd like to add this sort of shell script to my profile.
Currently I'm using some info from this page http://sos.blog-city.com/mac_os_x__bash_customize_your_terminal_prompt_a_little_color.htm to address some of this info locally.
Thanks in advance.
Get a copy of the git completion script. You can get this from git itself, or if you have a Linux box handy you could even just copy it from there (it'll probably be /etc/bash_completion.d/git). Then, arrange for this to get "sourced" by bash. You can do this by adding something like this to your .bashrc:
. /usr/local/git-completion
(assuming you named the file /usr/local/git-completion on your Mac).
Finally, you'll want to adjust your prompt. Also in your .bashrc, add something like:
export PS1='[\w$(__git_ps1 "|%s")]\$ '
Here's a blog post (not by me) that talks about this (and some other related stuff) in more detail: http://blog.bitfluent.com/post/27983389/git-utilities-you-cant-live-without
OK, I experimented with this after you pointed me in the right direction, my google searches got more refined results.
A lot of people point to the post you shared with me, like here: https://superuser.com/questions/31744/how-to-get-git-completion-bash-to-work-on-mac-os-x but I found some other jewels like these, which I didn't use but were informative: jeetworks.org/node/10 , jonmaddox.com/2008/03/13/show-your-git-branch-name-in-your-prompt/ .
I needed some different guidance on installing git.completion because I use homebrew which I found here: https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion which covers several ways to install it.
Finally, my bash/terminal has been a bit pokey so I upgraded to the latest bash with these instructions before I meshed with any of this: milkbox.net/brace_completion_snow_leopard_upgrading_bash/ and got some great speed improvement.
I ended up having to rebuild my profile script very carefully but with trail and error (because of differences between Bash 3 and 4, and some syntax errors)- now it looks great, and does the job.
Thanks again.
Sorry about above the security restraints of the site, restrict me (since I'm a newb) to 2 links to combat spam.
You just need 2 steps to do it.
Step.1:
Open ~/.bash_profile in your favorite editor and add the following content to the bottom.
For me it is like
emacs ~/.bash_profile
Step.2:
Add the following content to the bottom.
function git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'}
export PS1='\h:\w$(git_branch) \u\$'
Done!
P.s:
If you want your terminal colorful, try the following content.
export PS1 = '\[\e[1;39m\]\h:\w\[\e[01;39m\]$(git_branch) \[\e[01;39m\]$ \[\e[0m\]'
Another option to get git branch/status info in your shell prompt is to use powerline-shell.
You can see what this looks like in this screenshot:
The magenta/green bar is the current branch name. Its color indicates whether the working directory is clean. There are also markers that appear when there are untracked files, or when there are commits to be pulled-from/pushed-to the upstream remote.
Powerline-shell is compatible with bash, zsh, and fish.

Resources