Skip to content

Using git-bash on windows #463

Closed
Closed

Description

@sslime336

I opened this issue not for bug reporting, just post my success experience configing and using toggleterm.nvim on windows as I think this would be a great help if anyone who wants to setup an env like me.

A very simple config:

require'toggleterm'.setup({
    open_mapping = '<C-\\>',
    start_in_insert = true,
    direction = 'float',
})

Then find a place you like to emit below:

vim.cmd [[let &shell = '"D:/Git/bin/bash.exe"']]
vim.cmd [[let &shellcmdflag = '-s']]

Then just press Ctrl + \

图片

I wish this would help, it works on my PC anyway :P

Activity

  1. Zooce commented on Jul 13, 2023

    @Zooce

    This was a lifesaver...thank you! Now I can actually use toggle term at work...

  2. akinsho commented on Jul 14, 2023

    @akinsho
    Owner

    @sslime336 thanks for posting this. There is actually a wiki which anyone should be able to edit on this repo so you can also add this there. Hopefully people also check this.

  3. sslime336 commented on Jul 14, 2023

    @sslime336
    Author

    Sure, that would be more appropriate :-)

  4. akinsho commented on Jul 14, 2023

    @akinsho
    Owner

    I'll close this out now but keep it pinned for other users

  5. pinned this issue on Jul 14, 2023
  6. F2BEAR commented on Jan 7, 2024

    @F2BEAR

    Hey, I tried the same using lazy.vim without success; do somebody know where should I place the vim.cmd conf?

  7. xavierforge commented on Jan 23, 2024

    @xavierforge

    @F2BEAR
    For lazy.vim you can set the following in your init.lua or other place you like:

    vim.o.shell = "D:/Git/bin/bash.exe"
    vim.o.shellcmdflag = "-s"
  8. Leeto1970 commented on Jan 25, 2024

    @Leeto1970

    @F2BEAR For lazy.vim you can set the following in your init.lua or other place you like:

    vim.o.shell = "D:/Git/bin/bash.exe"
    vim.o.shellcmdflag = "-s"

    @eatPizza311 Hello, what's means "-s"? I look up ":help shellcmdflag", vim show default "-c", and "/s /c" in windows.

  9. F2BEAR commented on Jan 25, 2024

    @F2BEAR

    @F2BEAR
    For lazy.vim you can set the following in your init.lua or other place you like:

    vim.o.shell = "D:/Git/bin/bash.exe"
    vim.o.shellcmdflag = "-s"

    This is exactly what I needed, thanks!

  10. xavierforge commented on Jan 29, 2024

    @xavierforge

    @OuyangIPC I'm not sure how toggle-term starts the terminal under the hood.
    But the Windows default "/s /c" will be considered as directory "/s" and "/c" in GitBash, which is not what we want.
    On the other hand, Setting shellcmdflag = -s will start GitBash in a non-interactive mode, and it works like a charm, haha.

  11. Leeto1970 commented on Feb 2, 2024

    @Leeto1970

    @OuyangIPC I'm not sure how toggle-term starts the terminal under the hood. But the Windows default "/s /c" will be considered as directory "/s" and "/c" in GitBash, which is not what we want. On the other hand, Setting shellcmdflag = -s will start GitBash in a non-interactive mode, and it works like a charm, haha.

    @eatPizza311 Thanks for you information, it's very helpful to me.

  12. sewbacca commented on Dec 30, 2024

    @sewbacca

    When I use shellcmdflag = -s, :!ls and friends does no longer work. When I use shellcmdflag = -c then toggleterm does no longer work. Did anyone encounter the same problem?

  13. sewbacca commented on Dec 30, 2024

    @sewbacca

    Okay I found a workarround. It is ugly, but it works:

    {
    	'akinsho/toggleterm.nvim',
    	version = "*",
    	config = function ()
    		local toggleterm = require 'toggleterm'
    
    		toggleterm.setup {}
    
    		vim.keymap.set({ 'n', 't' }, "<C-\\>", function ()
    			vim.o.shellcmdflag = '-s'
    			vim.cmd.ToggleTerm()
    			vim.o.shellcmdflag = '-c'
    		end)
    	end
    }
  14. Leeto1970 commented on Dec 31, 2024

    @Leeto1970

    Okay I found a workarround. It is ugly, but it works:

    {
    	'akinsho/toggleterm.nvim',
    	version = "*",
    	config = function ()
    		local toggleterm = require 'toggleterm'
    
    		toggleterm.setup {}
    
    		vim.keymap.set({ 'n', 't' }, "<C-\\>", function ()
    			vim.o.shellcmdflag = '-s'
    			vim.cmd.ToggleTerm()
    			vim.o.shellcmdflag = '-c'
    		end)
    	end
    }

    This is what I used configure:
    for toggleterm:

    return {
        {
            'akinsho/toggleterm.nvim',
            version = "*",
            opts = function()
                return {
                    require('toggleterm').setup{
                        open_mapping = '<C-\\>',
                        autochdir = false,
                        start_in_insert = true,
                        shell = vim.o.shell,
                        direction = 'float',
                        float_opt = {
                            border = 'shadow',
                            width = 80,
                            heigh = 120,
                            title_pos = 'center',
                        }
                    }
                }
            end,
        }
    }
    

    for neovim options:

    if vim.fn.has('win64') == 1 or vim.fn.has('win32') == 1 then
      vim.opt.shellquote = "\""
      vim.opt.shellxquote = "\""
      vim.opt.shellcmdflag = "-c"
    end
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions