Mostrando entradas con la etiqueta bash. Mostrar todas las entradas
Mostrando entradas con la etiqueta bash. Mostrar todas las entradas

4 de agosto de 2015

Pimp my GIT: Improving GIT command line (cli) interface and usage

Aloha!


Following up yesterday's post, here goes another set of tricks I have done to my GIT setup.

To begin with, add this code to yhe .git/config file of your git repo clone:



Once you do that, you'll see things like colors when running a "git status":




You'lll also be able to use git command shortcuts, like:

- "git st" instead of "git status"
- "git ci" instead of "git commit"
(etc!)


Logs will look much more sexy and colorful.

You'll see diffs with colors and with a much more user-friendly format:





When running "git branch", you'll see the current branch highlighted and the local branches clearly marked in yellow:



And remote branches in green:




That's all for today, folks!


Cheers!

3 de agosto de 2015

Setting sail towards an awesome GIT experience

Here goes a bundle of tricks and treats for a better GIT experience:

Some years ago I found something like that I'm going to show you and, eventually, I assembled a series of scripts (some things I did, some things that I found on the web); they do various things with bash, which are sweet.

What things?


  • Automatically detects if you are in a folder belonging to a git repo, and, in the case it is, the prompt display relevant information that is repo: branch and state. Example:




In this case depicted, I was on the branch "master" and I had modified files (hence the "m") and files I deleted (hence the "d").


  •  Another cool thing is to have tab completion (that pressing the tab key with a half-written command you get all the options to complete the command -or the command being automatically completed if there was just one choice-).


Imagine that applied to branch names, git commands and Django commands (like "python manage.py runserver" for example). Sweet, isn't it?


  • Some other sweetnesses included:
    • Increase the size of the history of bash, but eliminating duplicates, so to do "ctrl r" in the console, we can look at the history of the commands that we did and found interesting results.
    • A long list of colors defined to directly save them in defining the prompt.
    • Etc!

The scripts, give me the scripts!

The first two put them right into your home folder.
The third file, call it the way your system get it right. For me it is .bash_profile. Put it right in your home with this name or copy its contents to your existing bash config file.
If you use Linux, you can do the same with .bashrc.

Note that the files have an underscore in the beginning of their filenames. Remove this underscore when placing the files, letting the names begin with a dot, as they are hidden files.


Cheers and May the bash be with you!!

26 de junio de 2014

How to merge two folders in Mac OS X or Linux


Short answer


Using the command line (Terminal):
cp -r -n ~/Desktop/src/* ~/Desktop/destination/
The command above adds the src content and the subdirectories to the destination without overwriting the content already present in the destination.

Long answer

Even if the content overlaps, you can still use cp to do it. Assume that you have two folders on your desktop: the src and the destination folders and you want to merge src into destination:
enter image description here
To merge, just do:
cp -r ~/Desktop/src/* ~/Desktop/destination/
NOTE When you use this, the content in src overwrites the content in the destination folder and adds the extra stuff that are missing in the destination. It shouldn't matter if you just want to add the missing files from src into destination.
ALSO it doesn't matter how many subdirectories are there, it will just go through each folder recursively and it will overwrite the content and will add the stuff that is missing in the destination folder.
BUT
PITFALL If you have huge files (like video files), you don't want to wait until everything is overwritten, it adds a lot of overhead.
PITFALL SOLUTION: Instead, you can use the -n flag to skip the overwriting:
cp -r -n ~/Desktop/src/* ~/Desktop/destination/
This is the description of the -n flag from the man page:
man cp
 -n    Do not overwrite an existing file.  (The -n option overrides any
       previous -f or -i options.)
Further Reading
  1. http://stackoverflow.com/questions/5088332/overhead-of-a-flag-in-cp-command
Source:

23 de septiembre de 2013

Mostrar el branch de GIT y el status actual en el shell prompt y más!

Algunos trucos para configurar nuestro setup local de GIT:

Hace algunos años encontré algo como eso y, con el tiempo, armé una serie de scripts (algunas cosas que hice yo, algunas cosas que fui encontrando en la web), que hacen varias cosas con bash, que están piolas.

¿Qué cosas?

- que se detecte automáticamente si se está en una carpeta perteneciente a un repo git, y que, en el caso que sí lo sea, el prompt muestre información relevante del repo en que se está: branch y estado. Ejemplo:



en ese caso, estoy en el branch "master" y tengo archivos modificados (por eso la "m") y archivos que borré (por eso la "d").

- otra cosa muy piola es tener tab completion (que al apretar tab, con un comando a medio escribir, se muestren opciones para completar ese comando -o que se completen, si hubiera una opción posible). Imaginen eso aplicado a nombres de branch, comandos git y comandos de django (como "python manage.py runserver", por ejemplo).

- Algunas cosas más, como:
-- aumentar el tamaño del history de bash, pero eliminando duplicados, para que al hacer "ctrl r" en la consola, podamos buscar en el historial de los comandos que hicimos y encontrar resultados interesantes.
-- Una larga lista de colores definidos, para directamente poder usarlos en la definición del prompt.

Etc!

Les paso adjuntas las scripts para hacer todo esto:


Las dos primeras las ponen derecho en el home. El .profile pueden ponerlo derecho en el home (si usan Mac y no tienen otro .profile armado) o copiar su contenido a su .profile existente. Si usan Linux, pueden hacer esto mismo con el archivo .bashrc.
(notar que tienen un underscore los archivos, a propósito, para que no sobreescriban cosas sin querer y para que no los tome el file browser como archivos ocultos).


Un abrazo y may the bash be with you (?),


21 de mayo de 2012

Find what you are looking for with grep + find + xargs

Sometimes (very often) you are looking for this particular word of string that you think is in one file of a given project... but you don't know which file, and the project has a zillion files. And you feel like crying.

Well, don't, that's what this post is for :)

Let's go for the command:

$ find -iname | xargs grep -in

Where:
[1] a folder name: for instance, to look from the current folder, use ".".
[2] for instance, for files ending in .py, use this: "*.py"
[3] a string to look for. Case insensitively.

Example: Let's look for the string "hello", case insensitively, between the files of the current folder and its subfolders, inside files with filename ending in .py:

$ find . -iname '*.py' | xargs grep -in 'hello'

The output will say the file(s) and line numbers in those files where 'hello' was found.

25 de octubre de 2011

Add forwards search to bash command history

Hi!

While using the bash console, the ctrl+r command comes extremely handy to search backwards through the command history.

But while searching backwards, we may want to be able to navigate both ways (i.e., backwards and forwards). This is not activated by default.

How to activate it? Just run this command:

$ stty -ixon -ixoff 

Tadaa! And now you can do ctrl+r and ctrl+s to navigate backwards and forwards.

You can also add this to your .profile file (in Mac OS X) or your .bashrc file (in Linux) for this to be available every time you open a Bash terminal.

Cheers!