Comments (3)
Xonsh is not a bourne-ish shell. You want @(random.random())
.
from xonsh.
Hello @ksaj!
In xonsh there are many ways to achieve this.
- Using alias:
aliases['rnd'] = lambda: __import__('random').randint(0,100) # one liner implementation
echo $(rnd)
# 23
echo $(rnd)
# 43
- Using function:
RND = lambda: __import__('random').randint(0,100)
echo @(RND())
# 43
echo @(RND())
# 53
See xonsh-cheetsheet for more ways.
from xonsh.
@ksaj You can use a @events.on_pre_prompt
on your .xonshrc
to emulate $RANDOM
.
@events.on_pre_prompt
def _():
import random
return random.randint(0, 32767)
Now you can use $RANDOM
like you would do in bash
.
16:48:50 47% jorge@localhost ~ @ $RANDOM
20034
16:48:51 47% jorge@localhost ~ @
from xonsh.
Related Issues (20)
- ` !(fzf | cat)` fails to capture output
- `!(fzf)` doesn't capture output reliably
- Crash from subprocess.run() after print() in alias HOT 2
- Python mode in an alias prevents redirection of subprocess mode command's output HOT 1
- a broken href link in doc HOT 1
- Support macOS history restore HOT 9
- Command Substitution Is Not Working As Intended HOT 2
- cd only respects HOME from os.environ and not XSH $HOME HOT 3
- Shell Fails With "command not found" When Using Specific Command Fields
- The Default Working Directory is `/usr/home/$USER` HOT 2
- EncodingWarning when running with PYTHONWARNDEFAULTENCODING=1
- Documentation: update Tutorial: Extensions (Xontribs) HOT 1
- exec in a xonsh script fails if the script was started with exec HOT 2
- readline issues when migrating from Python3.11 to Python3.12 (macOS) HOT 5
- Cython debugging does not work with xonsh as login shell
- history errors when using `sudo`
- termios.error after invoking subprocess in pythonanywhere
- Running a command in a subshell re-runs the xonshrc, but only when using redirection
- Inner shell execution (with `$`) triggers an a trailing `\n` that shouldn't be there HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xonsh.