-1

I have an alias alias new='misc.sh new' that works fine in the shell. The script misc.sh has a few functions one is named 'new'. When the alias is called from vim :! new arg I get this syntax error:

syntax error near unexpected token `('

This is the first function in the script misc.sh, the syntax error points to this function. I don't think the problem is this function though.

#!/usr/bin/env bash

updatem(){ #both
#update all python modules
echo 'Outdated packages are'
pip3 list --outdated
for p in $(pip3 list -o --format freeze); do pip3 install -U ${p%%=*}; done
}
OUT=$(date +%m-%d-%H-%M-%S)

tags(){ #both
echo 'Another function'
}

new(){
echo 'This is my function'
}

I have tried this and it does not work:

new(){ misc.sh new; }

I don't know why it works fine in the command line but not in vim.

ritchie
  • 405
  • 1
  • 4
  • 12
  • Is there a reason you reuse `new` so much? It probably will still work, but makes it confusing to understand and now to debug. – wxz Apr 07 '21 at 13:22
  • 1
    Does this answer your question? [How to make .bashrc aliases available within a vim shell command? (:!...)](https://stackoverflow.com/questions/4642822/how-to-make-bashrc-aliases-available-within-a-vim-shell-command) – wxz Apr 07 '21 at 13:38
  • @wxz Even if I change 'new' to 'foobar' or whatever else it does not work. I can access the alias in vim or any alias in vim like ```ll```, that's not the problem. The problem is I'm getting a syntax error. – ritchie Apr 07 '21 at 14:10
  • Can you include the lines in your `misc.sh` file up to where the syntax error is? – wxz Apr 07 '21 at 14:17
  • @wxz updatem(){ #both #update all python modules echo 'Outdated packages are' pip3 list --outdated for p in $(pip3 list -o --format freeze); do pip3 install -U ${p%%=*}; done } – ritchie Apr 07 '21 at 14:35
  • @wxz I added to the question, much easier to read. – ritchie Apr 07 '21 at 14:37
  • Do you have a shebang in the `misc.sh` file or is `updatem()` the first line in the file? – wxz Apr 07 '21 at 14:46
  • @wxz I have ```#!/usr/bin/env bash``` and I have ```shopt -s expand_aliases``` in ~/.bash_aliases which makes aliases work and I have in my vimrc ```let $BASH_ENV= "~/.bash_aliases"``` I already changed the bang to ```#!/bin/bash```. – ritchie Apr 07 '21 at 14:51
  • Can you add all that to your post exactly as it is in your `.sh` file? There's a chance a typo happening before your function is causing this weird error. Sorry for all the requests – wxz Apr 07 '21 at 14:56
  • @wxz That's fine no problem, I understand these are hard to troubleshoot when there are so many factors involved. I added it. – ritchie Apr 07 '21 at 15:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230853/discussion-between-wxz-and-ritchie). – wxz Apr 07 '21 at 15:06
  • @wxz How about I make you a repo and you can clone it into a new account ? Will take me a while to do this but would be much easier for you and me. – ritchie Apr 07 '21 at 15:15
  • I created a [chat](https://chat.stackoverflow.com/rooms/230853/discussion-between-wxz-and-ritchie), let's talk there? – wxz Apr 07 '21 at 15:18

1 Answers1

0

After working with OP, we found that in several places, OP had repeated, conflicting names. For instance, in one place alias new was used in .bash_aliases and separately a function new() was defined in a bash script.

The solution was to rename the aliases from the functions to avoid conflicts.

wxz
  • 2,254
  • 1
  • 10
  • 31