Run shell and type output I am using iTerm2. I would like to have a keyboard shortcut which runs a command and types the output at the current cursor.

Example: I have a function branchName which returns/prints the current folder's branch name. I want the branch name to be written to the shell (iTerm2) by pressing cmdB.
Open iTerm2 preferences and go to Profiles tab. Select your desired profile and go to Keys tab. Tap plus sign (+) and type the following:


Keyboard Shortcut: ⌘cmd+B
Action: Send Text
In the next line add the following command: git name-rev --name-only HEAD\n




After that, when you hit ⌘cmd+B, iTerm send that command to your terminal and will return your current branch.

$ git name-rev --name-only HEAD
master