Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container-fluid">
	<div class="row">
		<div class="col-sm-12" id="app">
			<h1>Calculadora chmod</h1>
			<small><a target="_blank" href="https://parzibyte.me/blog">parzibyte.me/blog</a></small>
			<div class="form-group">
				<input placeholder="Escribe el nombre del archivo o directorio" v-model="nombreArchivo" class="form-control" type="text">
			</div>
			<label for="conDirectorio">
				<input v-model="conDirectorio" type="checkbox" id="conDirectorio"> ¿Es un directorio?
			</label>
			<label for="conSudo">
				<input v-model="conSudo" type="checkbox" id="conSudo"> ¿Con sudo?
			</label>
			
			<br>
			<strong>Nota: puedes hacer click en Dueño, Grupo o Resto del mundo para seleccionar los 3 permisos</strong>
			<br>
			<span @click="marcarTodosLosDe('owner')" class="badge badge-success cursor-manita">Dueño</span>
			<div class="form-group">
				<label for="ownerRead"><input v-model="permisos.owner.lectura" id="ownerRead" type="checkbox"> Lectura (r)</label>
				<label for="ownerWrite"><input v-model="permisos.owner.escritura" id="ownerWrite" type="checkbox"> Escritura (w)</label>
				<label for="ownerExecute"><input v-model="permisos.owner.ejecucion" id="ownerExecute" type="checkbox"> Ejecución (x)</label>
			</div>
			<span @click="marcarTodosLosDe('group')" class="badge badge-warning cursor-manita">Grupo</span>
			<div class="form-group">
				<label for="groupRead"><input v-model="permisos.group.lectura" id="groupRead" type="checkbox"> Lectura (r)</label>
				<label for="groupWrite"><input v-model="permisos.group.escritura" id="groupWrite" type="checkbox"> Escritura (w)</label>
				<label for="groupExecute"><input v-model="permisos.group.ejecucion" id="groupExecute" type="checkbox"> Ejecución (x)</label>
			</div>
			<span @click="marcarTodosLosDe('all')" class="badge badge-danger cursor-manita">Resto del mundo</span>
			<div class="form-group">
				<label for="allRead"><input v-model="permisos.all.lectura" id="allRead" type="checkbox"> Lectura (r)</label>
				<label for="allWrite"><input v-model="permisos.all.escritura" id="allWrite" type="checkbox"> Escritura (w)</label>
				<label for="allExecute"><input v-model="permisos.all.ejecucion" id="allExecute" type="checkbox"> Ejecución (x)</label>
			</div>
			<div class="form-group">
				<div class="alert alert-success">
					<strong>El comando con números octales es:</strong>
					<br>
					<code>{{comando}}</code>
					<br>
					<strong>Y con letras:</strong>
					<br>
					<code>{{comandoConLetras}}</code>
				</div>
			</div>
			
		</div>
		<p>
			Referencia: <a target="_blank" href="https://es.wikipedia.org/wiki/Chmod">Wikipedia</a>
		</p>
	</div>
</div>
              
            
!

CSS

              
                .cursor-manita{
	cursor: pointer;
}
              
            
!

JS

              
                new Vue({
	el: "#app",
	watch: {
		conDirectorio(){
			this.generar();
		},
		conSudo(){
			this.generar();
		},
		nombreArchivo(){
			this.generar();
		},
		permisos: {
			handler(valor){
				this.generar();
			},
			deep: true,
		}
	},
	data: () => ({
		comando: "",
		comandoConLetras: "",
		nombreArchivo: "",
		conSudo: false,
		conDirectorio: false,
		permisos: {
			owner: {
				lectura: false,
				escritura: false,
				ejecucion: false,
			},
			group: {
				lectura: false,
				escritura: false,
				ejecucion: false,
			},
			all: {
				lectura: false,
				escritura: false,
				ejecucion: false,
			},
		}
	}),
	methods: {
		marcarTodosLosDe(quien){
			for(let clave in this.permisos[quien]){
				if(this.permisos[quien].hasOwnProperty(clave)){
					this.permisos[quien][clave] = true;
				}
			}
		},
		generar(){
			let prefijoSudo = this.conSudo ? "sudo " : "",
				recursivo = this.conDirectorio ? "-R " : "",
				nombreArchivo = ` "${this.nombreArchivo}"`;
			let comandoOctal = prefijoSudo + "chmod " + recursivo + this.binarioAOctal(this.obtenerPermisoBinario("owner"));
			comandoOctal += this.binarioAOctal(this.obtenerPermisoBinario("group"));
			comandoOctal += this.binarioAOctal(this.obtenerPermisoBinario("all"));
			comandoOctal += nombreArchivo;
			this.comando = comandoOctal;
			
			let comandoConLetras = prefijoSudo + "chmod " + recursivo + "u=" + this.obtenerPermisoComoLetras("owner");
			comandoConLetras += ",g=" + this.obtenerPermisoComoLetras("group");
			comandoConLetras += ",o=" + this.obtenerPermisoComoLetras("all") + nombreArchivo;
			this.comandoConLetras = comandoConLetras;
		},
		binarioAOctal(binario){
			return parseInt(binario, 2).toString(8);
		},
		obtenerPermisoComoLetras(quien){
			let letras = "";
			let p = this.permisos[quien];
			if(p.lectura) letras+="r";
			if(p.escritura) letras+="w";
			if(p.ejecucion) letras+="x";
			return letras;
		},
		obtenerPermisoBinario(quien){
			let binario = "";
			let p = this.permisos[quien];
			binario += p.lectura ? "1" : "0";
			binario += p.escritura ? "1" : "0";
			binario += p.ejecucion ? "1" : "0";
			return binario;
		}
	}
});
              
            
!
999px

Console