Skip to main content

All Questions

Tagged with
2 votes
0 answers
47 views

Can't unalias then redefine as a function in the same conditional [duplicate]

Here is a simplified implementation of an issue in my bash/zsh aliases file: alias foobar='echo bar' # this is out of my control if true; then unalias foobar echo we got inside the conditional ...
Adam Katz's user avatar
  • 4,132
1 vote
2 answers
119 views

Start interactive function definition from shell-script

Using zsh or bash, I want to run a script that may prompt the user for multiple commands and store them as a function, however I'm finding that eval "function $FNCNAME() {" or echo "...
Joakim Hagen's user avatar
1 vote
1 answer
245 views

Run `git commit -m` with single quotes in zsh

I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m 'My $message here!'. I tried to write a ...
Justin Breen's user avatar
1 vote
2 answers
135 views

String Length Always Returns 2 in ZSH Function

I'm trying to bowdlerize email addresses in a fixed length text file by generating a random string the same length as the input. I'm passing the string as a backreference in sed. To simplify, this ...
Paul Joiner's user avatar
0 votes
1 answer
258 views

How to store command with option on variable of a function in zsh?

I'm trying to learn bash scripting using freeCodeCamp tutorial for beginners on YouTube. I'm stuck at the point where he shows how to create a function. He saved on a variable a command with an option ...
Paul Marcelin Bejan's user avatar
2 votes
1 answer
360 views

printf "%.3f" ${variable with newlines} - error with \n

Like HERE I have a file.csv with numbers in quotes: "0.2" "0.3339" "0.111111" To round the number (3 decimals) this solutions works great: printf "%.03f\n" $(...
R 9000's user avatar
  • 167
1 vote
1 answer
315 views

How to write a function that takes an argument string that does not need to be quoted?

I'm writing a function, adding it to ~/.zshrc on my Mac. It's in order to more quickly handle commands to youtube-dl. I have this: function dlv() { cd /Users/admin/Downloads youtube-dl ...
Alfie Stoppani's user avatar
4 votes
1 answer
183 views

Why do backgrounded commands in Zsh functions not show correctly in jobs?

In Bash 5.2, the output of jobs after either of the following is identical modulo job numbers: sleep 3 # press C-z s() { sleep 3; } s # press C-z In both, jobs produces something like [1]+ Stopped ...
D. Ben Knoble's user avatar
1 vote
2 answers
1k views

How can I/Should I default flags when running a command?

For context, I'm using zsh. Every time I use locate, I want to pass the -i and -A flags. Usually, if I can get away with it, I create an alias with the same name as the existing command to do this. ...
Daniel Kaplan's user avatar
1 vote
2 answers
487 views

zsh: alias or shell function to only echo its command line, including shell control characters

Using zsh, I'd like to create an alias or a shell function that operates as follows: I want this alias or shell function to echo its command line without honoring any shell control characters such as &...
HippoMan's user avatar
  • 687
5 votes
1 answer
2k views

zsh: pass variable by reference, and modify its value (like bash's local -n namerefs)?

Is it possible to pass a variable to a zsh function, and modify its value without using eval? I came across a bash way to do that: local -n: https://stackoverflow.com/a/50281697
codepoet's user avatar
  • 626
1 vote
1 answer
181 views

zsh parameter substitution

This page has a demo function as follows: ~inews> namedir () { $1=$PWD ; : ~$1 } But when I try it on my machine, it produces the following error: namedir: no such file or directory: test=/home/...
In_Quisity's user avatar
1 vote
2 answers
899 views

How to pass zsh alias function to pipe

I have a zsh alias: gitbs() { git branch | grep -- $1 } And I would like to pass the result into git checkout, for example: git checkout | gitbs state How can I make this work?
Pankov's user avatar
  • 13
2 votes
0 answers
97 views

zsh: Make getting the value of a variable invoke a function

I like to use a "getter" function for some variable foo, such that using "$foo" is equivalent to "$(foo-getter)". It think this should be possible, as $EPOCHREALTIME ...
HappyFace's user avatar
  • 1,684
1 vote
1 answer
581 views

execute command on all visible shells

I'm currently running a tiling window manager and I want to be able to use a custom function that is equivalent to one I had when I was using tmux that allowed me to run a command in all visible ...
Thermatix's user avatar
  • 361

15 30 50 per page
1
2 3 4 5