Git Product home page Git Product logo

hyper-init's Introduction

hyper-init heading

The ultimate and most complete extension to initialize commands before and after Hyper terminal starts

become a patron or sponsor issuehunt url npm version downloads mentioned in awesome list

With hyper-init you can perform as many commands as you want, before and after Hyper terminal starts, using rules that define when your commands should run.

hyper-init gif

Table of Contents

Installation

If you don't have Hyper, install it from here.

So, type the following on Hyper:

hyper i hyper-init

Configuration

init

hyper-init can be configured within the config object in the ~/.hyper.js configuration file.

All you have to do to get started is to create an array of objects called init, like this:

init: [
  {
    rule: 'once',
    commands: ['cd ~/Desktop', 'ls'],
    allowedShells: ['zsh', 'bash']
  }
]

Your ~/.hyper.js configuration file should look like this:

module.exports = {
  config: {

    // add hyper-init configuration like this:
    init: [
      {
        rule: 'once',
        commands: ['cd ~/Desktop', 'ls'],
        allowedShells: ['zsh', 'bash']
      },
      {
        rule: 'windows',
        commands: ['echo This is only executed on New Windows!']
      },
      {
        rule: ['splitted', 'tabs', 'windows'],
        commands: ['echo Hey, I can set an array of rules!']
      }
    ]
  },

  plugins: ['hyper-init']

}

Rules

A string or array that defines when you want your commands to run.

Rule Description
once executes your commands only at Hyper starts
windows executes your commands only when a new Hyper window opens
tabs executes your commands only when a new tab is opened
splitted executes your commands only when a new pane is opened
all executes your commands every time a terminal opens

Commands

An array with your shell commands to run.
You can perform as many commands as you would like.

Example:

commands: ['cd ~/Desktop', 'ls']

Allowed Shells

An array of allowed shells to restrict the commands to be executed.

Example:

allowedShells: ['zsh', 'bash']

You can omit this property or let the array empty if you would like to allow the commands run for all shells.

clearCommand

hyper-init can infer the command to clear the screen for a small number of terminals. If it can't infer the command, hyper-init clears the terminal buffer using printf "\\033[H". You can set it manually adding the clearCommand: '' property within the config object. For example:

module.exports = {
  config: {
    clearCommand: 'reset'
  }
}

commandSeparator

hyper-init uses && as the default separator for commands. For known terminals, hyper-init can infer the separator. You can also set it manually by adding the commandSeparator: '' property within the config object, but this overrides for all terminals, even ones that don't support that delimiter. For example:

module.exports = {
  config: {
    commandSeparator: ' ++ ' // For an arbitrary terminal that uses `++`
  }
}

Contributing

Contributions are always welcome.

There's a bunch of ways you can contribute to this project, like by:

  • 🔌 Creating new features
  • 👋 Requesting a feature
  • 🪲 Reporting a bug
  • 📄 Improving this documentation
  • 🚨 Sharing this project and recommending it to your friends
  • 💵 Supporting this project on Patreon
  • 🐛 Funding an issue on IssueHunt
  • 🌟 Dropping a star on this repository

And hyper-init's ability to infer the clearCommand and commandSeparator is based on its relatively small dictionary. Feel free to add more definitions for terminals not listed in shells.js.

KNOWN_SHELLS = {
  [...]
  shellName: {
    separator: '',
    clearCommand: ''
  }
  [...]
}
  • shellName should be replaced with the name of the shell you want to target (lowercase)
  • The value of separator should be the separator for multiple statements on one line (e.g. ' && ') as a string
  • The value of clearCommand should be the command to clear the target shell (e.g. 'cls') as a string
KNOWN_SHELLS = {
  [...]
  powershell: {
    separator: '; ',
    clearCommand: 'Clear-Host'
  }
  [...]
}

License

MIT © Dalton Menezes

hyper-init's People

Contributors

daltonmenezes avatar jenhausu avatar nightmarlin avatar wushuo894 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hyper-init's Issues

Command to open new tabs and have hyper-init act on them

First, thank you for the extension - it is fantastic! I was wondering whether there's a way for hyper-init to basically set all my initial tabs. Right now, all commands are executed in the same pane. Can they be executed in different panes? For example:

  • When Hyper is opened
    • cd of the current tab (command 1)
    • Open a new tab (automatically)
    • Execute another command (command 2)

Problem when you have more than one cross-platform task/shells

Running Commands

I love to personalize my stuff, and one of them is my Hyper terminal, thanks to this plugin I can execute commands at the Init of my Terminal and when I open/split a new tab, showing my system info or ASCII art.

My Init Code
init: [
      {
        rule: "once",
        commands: [
          "Set-Prompt",
          "Set-Theme Material",
          "clear",          
          "Write-Host -ForegroundColor Green '                      Welcome Back                     '",
          "$Model = (Get-CimInstance win32_computersystem).Model",
          "$Manu = (Get-CimInstance win32_computersystem).Manufacturer",
          "$PC = (Get-CimInstance win32_computersystem).Name",
          "$User = (Get-CimInstance win32_computersystem).PrimaryOwnerName",
          "Write-Host -ForegroundColor DarkRed '                                                        ' -NoNewline;Write-Host -ForegroundColor Blue $PC -NoNewLine; Write-Host -ForegroundColor DarkYellow '@' -NoNewLine; Write-Host -ForegroundColor Blue $User",
          "Write-Host -ForegroundColor DarkRed ' ██ ▄█▀▓██   ██▓ ▒█████   ███▄    █  ▄▄▄      ▒██   ██▒ ' -NoNewline;Write-Host -ForegroundColor Blue 'Manufacturer: ' -NoNewline;Write-Host -ForegroundColor DarkYellow $Manu",
          "Write-Host -ForegroundColor DarkRed ' ██▄█▒  ▒██  ██▒▒██▒  ██▒ ██ ▀█   █ ▒████▄    ▒▒ █ █ ▒░ ' -NoNewline;Write-Host -ForegroundColor Blue 'Model: ' -NoNewline;Write-Host -ForegroundColor DarkYellow $Model",
          "Write-Host -ForegroundColor DarkRed '▓███▄░   ▒██ ██░▒██░  ██▒▓██  ▀█ ██▒▒██  ▀█▄  ░░  █   ░ '",
          "Write-Host -ForegroundColor DarkRed '▓██ █▄   ░ ▐██▓░▒██   ██░▓██▒  ▐▌██▒░██▄▄▄▄██  ░ █ █ ▒  '",
          "Write-Host -ForegroundColor DarkRed '▒██▒ █▄  ░ ██▒▓░░ ████▓▒░▒██░   ▓██░ ▓█   ▓██▒▒██▒ ▒██▒ '",
          "Write-Host -ForegroundColor DarkRed '▒ ▒▒ ▓▒   ██▒▒▒ ░ ▒░▒░▒░ ░ ▒░   ▒ ▒  ▒▒   ▓▒█░▒▒ ░ ░▓ ░ '",
          "Write-Host -ForegroundColor DarkRed '░ ░▒ ▒░ ▓██ ░▒░   ░ ▒ ▒░ ░ ░░   ░ ▒░  ▒   ▒▒ ░░░   ░▒ ░ '",
          "Write-Host -ForegroundColor DarkRed '░ ░░ ░  ▒ ▒ ░░  ░ ░ ░ ▒     ░   ░ ░   ░   ▒    ░    ░   '",
          "Write-Host -ForegroundColor DarkRed '░  ░    ░ ░         ░ ░           ░       ░  ░ ░    ░   '",
          "Write-Host -ForegroundColor DarkRed '        ░ ░                                             '",
          "Write-Host -ForegroundColor DarkRed '                                                        '",
        ],
      },
      {
        rule: ["windows", "tabs", "splitted"],
        commands: ["Set-Prompt", "Set-Theme Material"],
      },
    ],

Issue

The problem is that when I open a new tab on Wsl or CMD or using another cross-platform task, the commands are still executed, no matter If I put "windows", on the rule init.

image

Question

Exist a config or what I need to do, to validate the cross-platforms task/shells when the terminal has to execute the commands?

Setting multiple rules for one command

Is there no way of setting multiple rules for one command?

e.g.

init: [
  {
    rule: 'once',
    commands: ['command 1']
  },
  {
    rule: ['splitted', 'once'],
    commands: ['command 2']
  }
]

Can't make this work on Windows 10

Am I doing something wrong?
I've added the configuration, just an example to see working but I only see this:

terminal

plugins: ["hyper-init"],
...
init: [
    {
      rule: 'once',
      commands: ['echo This is only executed on New Windows!']
    }
  ],
...

I've removed all others plugins just to make sure but still.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.